Elastic search without errors

I would like to know if there is a way to point to the search for an elastic image that I am not opposed to missing or erroneous indexes in my search query. In other words, I have a query that tries to query 7 different indexes, but one of them may be missing depending on the circumstances. I want to know that if there is a way to say, forget about the broken and get the results of the other 6 indices?

SearchRequestBuilder builder = elasticsearchClient.getClient().prepareSearch(indices) .setQuery(Query.buildQueryFrom(term1, term2)) .addAggregation(AggregationBuilders.terms('term') .field('field') .shardSize(shardSize) .size(size) .minDocCount(minCount)); 

As an example, you can find the above.

+6
source share
2 answers

Take a look at the ignore_unavableable parameter, which is part of the multi index syntax. This has been available since at least version 1.3 and allows you to ignore missing or closed indexes when performing a search (among other operations with multiple indexes).

It is displayed in the Java API IndicesOptions . Looking through the source code, I found that there is a setIndicesOptions() method on the SearchRequestBuilder used in the example. You need to pass it an instance of IndicesOptions .

In the IndicesOptions class, there are various static factory methods for instantiating with your desired parameters. It will probably be more profitable for you to use the more convenient lenientExpandOpen() factory method (or the legacy version of lenient() , depending on your version), which sets ignore_unavailable = true, allow_no_indices = true and expand_wildcards = open.

Here is a modified version of the sample request that should provide the behavior you are looking for:

 SearchRequestBuilder builder = elasticsearchClient.getClient().prepareSearch(indices) .setQuery(Query.buildQueryFrom(term1, term2)) .addAggregation(AggregationBuilders.terms('term') .field('field') .shardSize(shardSize) .size(size) .minDocCount(minCount)) .setIndicesOptions(IndicesOptions.lenientExpandOpen()); 
+6
source

Have you tried using Index Aliases ?

Instead of referring to individual aliases, you can specify a single index value. There may be several indexes behind this.

Here I add two indexes to the alias and remove the missing / broken:

 curl -XPOST 'http://localhost:9200/_aliases' -d ' { "actions" : [ { "remove" : { "index" : "bad-index", "alias" : "alias-index" } }, { "add" : { "index" : "good-index1", "alias" : "alias-index" } }, { "add" : { "index" : "good-index2", "alias" : "alias-index" } } ] }' 
+1
source

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


All Articles