简体   繁体   中英

How to get the data from multiple index in elastic search

I have a three index, all three index have a diff structure of document(nested), I tried to join the index's,But in ES there is no joins.So, how can i get the data from multiple index's through java high level api??

Any help will be appreciate, thanks in adavnce

SearchRequest searchRequest = new SearchRequest("index_1","index_2","index_3");
SearchSourceBuilder sourceBuilder = new SearchSourceBuilder(); 
sourceBuilder.query(QueryBuilders.termQuery("user", "kimchy"));
SearchResponse searchResponse = client.search(searchRequest, RequestOptions.DEFAULT);

You can query multiple Elasticsearch indices in one search operation. The indices can be specified with wildcard patterns, or by listing multiple indices using commas as separators.

But with Client API(Java high level api), You've to convert the index names inside SearchRequest into an array of Strings. Java varargs expects an Array. Not sure but something like below.

String[] indexArray = new String[]{"index_1","index_2","imdex_3"}
SearchRequest searchRequest = new SearchRequest(indexArray);

If it doesn't help the try with Multisearch API, See : https://www.elastic.co/guide/en/elasticsearch/client/java-rest/master/java-rest-high-multi-search.html#java-rest-high-multi-search

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM