# Refreshing index preventing results being returned?

**URL:** <https://discuss.elastic.co/t/refreshing-index-preventing-results-being-returned/15047>\
**Category:** Elasticsearch\
**Created:** [December 29, 2013, 5:18pm UTC](https://discuss.elastic.co/t/refreshing-index-preventing-results-being-returned/15047 "2013-12-29T17:18:55Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Frederick\_Cheung](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/frederick_cheung/32/1874_2.png) [@Frederick\_Cheung](https://discuss.elastic.co/u/Frederick_Cheung)\
**Post date:** [December 29, 2013, 5:18pm UTC](https://discuss.elastic.co/t/refreshing-index-preventing-results-being-returned/15047/1 "2013-12-29T17:18:55Z")

</div>

Hi,

I've been having a problem where refreshing an index at the wrong point  
seems to prevent results being returned. I've managed to cut down my  
problem to the following sequence:

```
curl -XDELETE 'http://localhost:9201/test__garments'

curl -XPOST 'http://localhost:9201/test__garments/garment/1' -d 

```

'{"id":1, "name":"Some Garment"}'  
curl -XPOST '[http://localhost:9201/test\_\_garments/\_refresh](http://localhost:9201/test__garments/_refresh)'  
curl -XPUT '[http://localhost:9201/test\_\_garments/verdict/\_mapping](http://localhost:9201/test__garments/verdict/_mapping)' -d  
'{"verdict":{"\_parent":{"type":"garment"},"properties":{"id":{"type":"integer"}}}}'  
curl -XPOST '[http://localhost:9201/test\_\_garments/verdict/1?parent=1](http://localhost:9201/test__garments/verdict/1?parent=1)'  
-d '{"id":1}'

```
curl -XPOST 'http://localhost:9201/test__garments/_refresh'
curl -XPOST 'http://localhost:9201/test__garments/verdict/_search' -d '
{
  "query": {
    "filtered": {
      "query": {
        "match_all": {}
      },
      "filter": {
          "has_parent": {
            "type": "garment",
            "query": {
              "match_all": {}
            }
          }
      }
    }
  }
}
  '

```

Should produce 1 result: I'm indexing a document (garment), adding a child  
document (verdict) and then querying for child documents that have a parent.

If I remove the first call to refresh then the search does return the  
expected document and everything behaves normally. If I leave that refresh  
in place then I get no results until I do something like

curl -XPOST localhost:9201/test\_\_garments/garment/1/\_update -d  
'{"script":""}'

Has anyone ever seen something like this before? I'm using ES 0.90.9 on OS  
X 10.9.1 (java -version is 1.7.0\_45). This seems to work fine on ES 0.20.6

- this showed up while I was (belatedly) testing upgrading to 0.90

Fred

--  
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/8310e078-052f-4c7a-a44c-6cf548266578%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/8310e078-052f-4c7a-a44c-6cf548266578%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![jprante](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jprante/32/44941_2.png) [@jprante](https://discuss.elastic.co/u/jprante)\
**Post date:** [December 29, 2013, 8:53pm UTC](https://discuss.elastic.co/t/refreshing-index-preventing-results-being-returned/15047/2 "2013-12-29T20:53:00Z")

</div>

Before the \_search, you can issue a

curl -XPOST '[http://localhost:9200/\_cache/clear?id\_cache=true](http://localhost:9200/_cache/clear?id_cache=true)'

to make it work.

See also [https://gist.github.com/jprante/8174209](https://gist.github.com/jprante/8174209)

Jörg

--  
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/CAKdsXoFtzbAYg%2BAfObW\_okt2Su746WzF8dHnkXN%2BkJmd-sW5ZQ%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAKdsXoFtzbAYg%2BAfObW_okt2Su746WzF8dHnkXN%2BkJmd-sW5ZQ%40mail.gmail.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Frederick\_Cheung](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/frederick_cheung/32/1874_2.png) [@Frederick\_Cheung](https://discuss.elastic.co/u/Frederick_Cheung)\
**Post date:** [December 29, 2013, 9:47pm UTC](https://discuss.elastic.co/t/refreshing-index-preventing-results-being-returned/15047/3 "2013-12-29T21:47:31Z")

</div>

On Sunday, December 29, 2013 8:53:00 PM UTC, Jörg Prante wrote:

> Before the \_search, you can issue a
> 
> curl -XPOST '[http://localhost:9200/\_cache/clear?id\_cache=true](http://localhost:9200/_cache/clear?id_cache=true)'
> 
> to make it work.
> 
> See also [Parent ID cache and \_refresh · GitHub](https://gist.github.com/jprante/8174209)

Thanks, that definitely helps narrow down what's happening although I don't  
see why the cache is in a stale state to begin with.

Fred

--  
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/61f2e51e-0bd5-4864-b7c4-54e9e063d0db%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/61f2e51e-0bd5-4864-b7c4-54e9e063d0db%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![jprante](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jprante/32/44941_2.png) [@jprante](https://discuss.elastic.co/u/jprante)\
**Post date:** [December 30, 2013, 9:03am UTC](https://discuss.elastic.co/t/refreshing-index-preventing-results-being-returned/15047/4 "2013-12-30T09:03:53Z")

</div>

You can also be safe when you create all the mappings first, then creating  
the docs.

Jörg

--  
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/CAKdsXoHq6gf67XcUJvxH66DTALCyhBGLCAHss%3DTO3ysLnGaxaA%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAKdsXoHq6gf67XcUJvxH66DTALCyhBGLCAHss%3DTO3ysLnGaxaA%40mail.gmail.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Frederick\_Cheung](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/frederick_cheung/32/1874_2.png) [@Frederick\_Cheung](https://discuss.elastic.co/u/Frederick_Cheung)\
**Post date:** [December 30, 2013, 9:15am UTC](https://discuss.elastic.co/t/refreshing-index-preventing-results-being-returned/15047/5 "2013-12-30T09:15:43Z")

</div>

> On 30 Dec 2013, at 09:03, "[joergprante@gmail.com](mailto:joergprante@gmail.com)" [joergprante@gmail.com](mailto:joergprante@gmail.com) wrote:
> 
> You can also be safe when you create all the mappings first, then creating the docs.

Ok. What I'd really like to understand is what is causing this, so I can decide whether this is just something affecting the setup on my unit tests (in which case doing something like changing the order in which all those steps happen is fine). If this could happen in production then I need a finer handle in what I need to avoid, because as it is this feels like a bug that I could accidentally trigger

Fred

> Jörg
> 
> --  
> You received this message because you are subscribed to a topic in the Google Groups "elasticsearch" group.  
> To unsubscribe from this topic, visit [https://groups.google.com/d/topic/elasticsearch/oD8EKEYeZuM/unsubscribe](https://groups.google.com/d/topic/elasticsearch/oD8EKEYeZuM/unsubscribe).  
> To unsubscribe from this group and all its topics, 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/CAKdsXoHq6gf67XcUJvxH66DTALCyhBGLCAHss%3DTO3ysLnGaxaA%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAKdsXoHq6gf67XcUJvxH66DTALCyhBGLCAHss%3DTO3ysLnGaxaA%40mail.gmail.com).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
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/55B67DC0-791D-44D7-8967-E6AAA3F1F0E4%40gmail.com](https://groups.google.com/d/msgid/elasticsearch/55B67DC0-791D-44D7-8967-E6AAA3F1F0E4%40gmail.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![jprante](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jprante/32/44941_2.png) [@jprante](https://discuss.elastic.co/u/jprante)\
**Post date:** [December 30, 2013, 9:55am UTC](https://discuss.elastic.co/t/refreshing-index-preventing-results-being-returned/15047/6 "2013-12-30T09:55:12Z")

</div>

The semantics of "\_refresh" is to execute a Lucene "maybeRefresh" with a  
force attribute. This might also affect ES ID cache access that is not part  
of the Lucene refresh operation.

There is an extra clear ID cache API beside refresh API, so that ES ID  
cache can be cleared by another API request. For convenience, it could be  
more comprehensible to include a clear ID cache operation into each refresh  
API request. On the other hand, invalidating caches can be expensive, so  
there are two API calls for good reason. So, it is a kind of interpretation  
what can be expected from a refresh API call. I would call it a glitch, and  
it seems specific to parent/child.

My rule of thumb: if you have a parent/child query on docs you created  
between different API forced refresh calls, call the clear ID cache API, so  
for the parent/child query, a valid ID cache will get populated again.

Maybe you should open an issue to get this tracked by the ES team, because  
the current behavior is not corresponding to a "least surprise" principle.

Jörg

--  
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/CAKdsXoFY4Dcd4hXzsf8k-vWZkpn7EsPTxhHxk-hTNK\_gUiq4Jg%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAKdsXoFY4Dcd4hXzsf8k-vWZkpn7EsPTxhHxk-hTNK_gUiq4Jg%40mail.gmail.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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:59am UTC](https://discuss.elastic.co/t/refreshing-index-preventing-results-being-returned/15047/7 "2017-07-06T01:59:03Z")

</div>


