4

I'm using ElasticSearch java client as a Maven dependency:

    <dependency>
        <groupId>org.elasticsearch</groupId>
        <artifactId>elasticsearch</artifactId>
        <version>1.7.1</version>
    </dependency>

I am doing search with multi-index, and I'm getting IndexMissingException and I want to ignore it using the parameter: 'ignore_unavailable' but I don't know how to use it, and don't found documentation about this.

https://www.elastic.co/guide/en/elasticsearch/reference/current/multi-index.html (link about ignore_unavailable)

I'm creating the search like this:

    SearchRequestBuilder srb = ess.getClient()
        .prepareSearch(generateIndex(query)) //generateIndex returns a array
        .setTypes("mytype")
        .setSearchType(SearchType.DFS_QUERY_AND_FETCH)
        .setPostFilter(FilterBuilders.rangeFilter("Time")
                .from(time1.toInstant(ZoneOffset.UTC))
                .to(time2.toInstant(ZoneOffset.UTC))
        )   
        .setFrom(0).setSize(RESULT_MAX).setExplain(true)
        //putHeader don't work...
       .putHeader("ignore_unavailable", true);   

How do I use ignore_unavalilable here?

2 Answers 2

10

You need to use setIndicesOptions(IndicesOptions) - eg.

.prepareSearch(generateIndex(query))
.setIndicesOptions(IndicesOptions.fromOptions(true, false, false, false))

You could also use IndicesOptions.lenientExpandOpen() instead of calling fromOptions().

Sign up to request clarification or add additional context in comments.

2 Comments

can you please provide some context, as to where can I set the indices options globally? in my case, elasticsearch is configured automatically with application.properties, so there is no other config file
These are query-time options, telling the searcher to ignore any indices that are missing. It's not a global application-level setting. Bear in mind this answer is quite old now, the answer from @Shivam below may be more useful to you.
1

In older versions of ES, we can use -

esClient.prepareSearch(allIndices)
        .setIndicesOptions(IndicesOptions.lenientExpandOpen())

In newer versions -

SearchRequest searchRequest = new SearchRequest(indices, searchSourceBuilder);
searchRequest.indicesOptions(IndicesOptions.lenientExpandOpen());

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.