Search elasticsearch search

Now I want to search for an identifier in a field.

builder.startObject().startObject(TYPE_SERIES).startObject("properties"); builder.startObject(ID) .field("type", "long") .field("store", "yes") .field("index", "analyzed") .field("analyzer", "test_analyzer") .endObject(); builder.startObject(TITLE) .field("type", "string") .field("store", "yes") .field("index", "analyzed") .field("analyzer", "test_analyzer") .field("boost", "10") .endObject(); 

I tried to search for ID as follows:

 .setQuery(QueryBuilders.multiMatchQuery(query, ID, TITLE)) 

By the way, I can get the result with id, instead I cannot search with a title. I'm just looking with an id to get the results.

So, I changed it like that. I used MultiSearchResponse to try to execute two child queries.

One

 .setQuery(QueryBuilders.idsQuery(TYPE).ids(query)) 

other

 .setQuery(QueryBuilders.multiMatchQuery(query, TITLE,DESCRIPTION)) 

Unfortunately, I just get the result with a title or description. If I search for an identifier, I cannot get any results.

================= I would like to perform like this

 curl -XGET localhost:9200/test/series/99 

I want to get results with id. Unfortunately, I do not know how to make this code with the JAVA API.

Please let me know. Thank you

+4
source share
2 answers

There is a _id field here in which you can search. So curl http://localhost:9200/_search?q=_id:99+AND+_type:series+AND+_index:test or http://localhost:9200/test/series/_search?q=_id:99 should do the trick.

+3
source

Like previous people, a complete example will help. But let your type of document you're looking for is a "series":

 .setQuery(QueryBuilders.idsQuery("series").addIds("99")); 

Or a little more fully:

 SearchResponse esResponse = esClient.prepareSearch("test") .setQuery(QueryBuilders.idsQuery("series").addIds("99")) .execute().actionGet(); 
+3
source

Source: https://habr.com/ru/post/1491884/


All Articles