# MultiSearchResponse Inconsistent State

**URL:** https://discuss.elastic.co/t/multisearchresponse-inconsistent-state/19073
**Category:** Elasticsearch
**Created:** [August 4, 2014, 3:54pm UTC](https://discuss.elastic.co/t/multisearchresponse-inconsistent-state/19073 "2014-08-04T15:54:43Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Serge\_Semichev](https://avatars.discourse-cdn.com/v4/letter/s/a8b319/32.png) [@Serge\_Semichev](https://discuss.elastic.co/u/Serge_Semichev)
#### Post date: [August 4, 2014, 3:54pm UTC](https://discuss.elastic.co/t/multisearchresponse-inconsistent-state/19073/1 "2014-08-04T15:54:43Z")

</div>

ElasticSearch clusters has 12 nodes, 12 shards and number\_of\_replicas is 0.

A Storm topology sends MultiSearch requests to ElasticSearch cluster in  
parallel using 10 Storm nodes.

The problem is the values of _response.getHits().getTotalHits()_ and  
_response.getHits().getHits().length_ are different for some of responses.  
(response.getHits().getTotalHits() \> 0 and  
response.getHits().getHits().length ==0)

So SearchResponse objects are in inconsistent state.  
It is a serious issue for our architecture because  
(response.getHits().getTotalHits() \> 0) means that there is a matched  
document but we cannot process it.

The queries are "filtered term queries".

Source Code:

public List queryBulk(List matchQueries) {  
MultiSearchRequestBuilder multiSearch =  
\_client.prepareMultiSearch();

```
    for (String query : matchQueries) {

        SearchRequestBuilder search = _client.prepareSearch(_index);

        search.setTypes(_type);
        search.setPreference("_primary");
        search.setVersion(true);
        search.setQuery(query);
        search.setSize(1);
        multiSearch.add(search);
    }

    List<FooBean> ret = new ArrayList<FooBean>(matchQueries.size());
    
    MultiSearchResponse sr = multiSearch.execute().actionGet();
    MultiSearchResponse.Item[] items = sr.getResponses();
    
    int number_of_results = 0;
    int number_of_success = 0;
    int number_of_failure = 0;
    
    for (int i = 0; i < items.length; i++) 
    {
        SearchResponse response = null;
        if (items[i] != null) response = items[i].getResponse();

        SearchHits hits = null;
        if (response != null) hits = response.getHits();

        long noOfHits = 0;
        if (hits != null) noOfHits = hits.getTotalHits();

        number_of_results++;
        
        if (noOfHits <= 0) {
            ret.add(null);
        } else {
            if (hits.getHits().length > 0) {
                SearchHit firstHit = hits.getAt(0);
                VoterBean result = new FooBean(firstHit.getId(), 

```

firstHit.getVersion(), firstHit.getSourceAsString());

```
                number_of_success++;
                
                ret.add(result);
            } else {
                LOG.info("Inconsistent State : No of Hits =" + noOfHits 

```

- " but content =" + hits.getHits().length + " . Query = " +  
matchQueries.get(i));

number\_of\_results +  
" / number\_of\_success: " + number\_of\_success + " /  
number\_of\_failure: " + number\_of\_failure);  
}

```
    return ret;
}

```

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/086d140b-4221-421b-bbd8-72a965348cf4%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/086d140b-4221-421b-bbd8-72a965348cf4%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [July 6, 2017, 1:10am UTC](https://discuss.elastic.co/t/multisearchresponse-inconsistent-state/19073/2 "2017-07-06T01:10:58Z")

</div>


