13

When i try to index data and then do query, all is good, but if i start my app and will do query without indexing before it i get that error

Exception in thread "main" org.elasticsearch.action.search.SearchPhaseExecutionException: Failed to execute phase [query_fetch], all shards failed at org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction.onFirstPhaseResult(TransportSearchTypeAction.java:272)
    at org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction$3.onFailure(TransportSearchTypeAction.java:224)
    at org.elasticsearch.search.action.SearchServiceTransportAction.sendExecuteFetch(SearchServiceTransportAction.java:307)
    at org.elasticsearch.action.search.type.TransportSearchQueryAndFetchAction$AsyncAction.sendExecuteFirstPhase(TransportSearchQueryAndFetchAction.java:71)
    at org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction.performFirstPhase(TransportSearchTypeAction.java:216)
    at org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction.performFirstPhase(TransportSearchTypeAction.java:203)
    at org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction$2.run(TransportSearchTypeAction.java:186)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:745)

Here is my code and settings of elasticsearch

    //  settings
    ImmutableSettings.Builder settings = ImmutableSettings.settingsBuilder();
    settings.put("client.transport.sniff", false);
    settings.put("path.home", "/path/to/elastic/home");
    settings.put("index.number_of_replicas", 0);
    settings.put("index.number_of_shards", 1);
    settings.put("action.write_consistency", "one");

    settings.build();
    // creating of node and client
    NodeBuilder nb = new NodeBuilder().settings(settings).local(true).data(true);
    Node node = nb.node();
    Client client = node.client();


    /*
         for (int i = 0; i <= 15; i++) {
         IndexResponse response = client.prepareIndex("twitter2", "tweet2", String.valueOf(i))
                .setSource(json1)
                .execute()
                .actionGet();
         }
   */

       searchRequestBuilder = client.prepareSearch("twitter2")
            .setTypes("tweet2")
            .setQuery(QueryBuilders.matchQuery("user", "user0"))
            .setQuery(QueryBuilders.matchQuery("message","message1"))
            .setExplain(true)
            .setSearchType(SearchType.DFS_QUERY_AND_FETCH).setSize(200);

        SearchResponse searchRespons = searchRequestBuilder.execute().actionGet(); // here is error

What is wrong in me settings?

5
  • You cant search an index/type that doesnt exist can you? By commenting out the indexing of twitter2/tweet2 you just dont have anything to search. Commented Sep 3, 2014 at 12:27
  • but i seen in path /path/to/elastic/home folders which contains indexes i create before and becouse it i suppose that it possible Commented Sep 3, 2014 at 12:34
  • do you need to set a path.data so that data is persistent to the same spot in between runs? Commented Sep 3, 2014 at 12:55
  • Now my app can find old data from elastic if before it i index something, therefore error is not in path(my opinion:) Commented Sep 3, 2014 at 13:00
  • anyone has any ideas ? Commented Sep 3, 2014 at 13:49

1 Answer 1

4

Can you try the same after adding a sleep for say 10 seconds after

Client client = node.client();

I feel Elasticsearch haven't recovered the shards before you have hit the search request. Even the admin call to "wait for yellow" should work for you

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

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.