# Are objects searchable after updates?

**URL:** <https://discuss.elastic.co/t/are-objects-searchable-after-updates/98562>\
**Category:** Elasticsearch\
**Created:** [August 28, 2017, 12:14pm UTC](https://discuss.elastic.co/t/are-objects-searchable-after-updates/98562 "2017-08-28T12:14:30Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![artelk](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/artelk/32/45644_2.png) [@artelk](https://discuss.elastic.co/u/artelk)\
**Post date:** [August 28, 2017, 12:14pm UTC](https://discuss.elastic.co/t/are-objects-searchable-after-updates/98562/1 "2017-08-28T12:14:30Z")

</div>

Imagine you have an object with a property X.  
The initial value of the property is 13.  
The object is searchable by a predicate "X \> 10".  
Someone modifies the property value to 42.  
Do we have guarantees that the object will be searchable by the same predicate after the update is sent to Elasticsearch? The used predicate matches both property values.

As far as I know internally the updates are transformed to delete/insert pairs.  
Can it be possible that the query with the predicate "X \> 10" will return nothing because the old state of the object has been already deleted and the new one isn't yet indexed?

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [August 29, 2017, 7:58am UTC](https://discuss.elastic.co/t/are-objects-searchable-after-updates/98562/2 "2017-08-29T07:58:06Z")

</div>

> [@artelk](#):
>
> Can it be possible that the query with the predicate “X \> 10” will return nothing because the old state of the object has been already deleted and the new one isn’t yet indexed?

Yes it is possible.

You may want to look at [?refresh | Elasticsearch Reference [5.5] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/5.5/docs-refresh.html#_literal_refresh_wait_for_literal_can_force_a_refresh)

---

<div class="post-metadata">

**Author:** ![artelk](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/artelk/32/45644_2.png) [@artelk](https://discuss.elastic.co/u/artelk)\
**Post date:** [August 29, 2017, 8:12am UTC](https://discuss.elastic.co/t/are-objects-searchable-after-updates/98562/3 "2017-08-29T08:12:16Z")

</div>

Thank you Mark.  
But how refresh could help?  
I was talking about query made in parallel by some other client.  
That client can get nothing just because the object is modifying, even if both values of X (old and new one) are greater than 10, correct? Can this be somehow solved without global lock?

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [August 29, 2017, 8:14am UTC](https://discuss.elastic.co/t/are-objects-searchable-after-updates/98562/4 "2017-08-29T08:14:48Z")

</div>

A refresh makes sure the document is searchable.

Wait for refresh is not a global lock. Is it the client waiting for that refresh on the shard it knows the data will exist on to make sure it gets a response.

---

<div class="post-metadata">

**Author:** ![artelk](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/artelk/32/45644_2.png) [@artelk](https://discuss.elastic.co/u/artelk)\
**Post date:** [August 29, 2017, 8:26am UTC](https://discuss.elastic.co/t/are-objects-searchable-after-updates/98562/5 "2017-08-29T08:26:50Z")

</div>

Ok, writer will wait until the object is searchable.  
But reader knows nothing about that and it will read in parallel.  
So I need to use global lock to sync the readers and the writer (that also do refresh), right?  
Or maybe there is a better solution?

---

<div class="post-metadata">

**Author:** ![artelk](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/artelk/32/45644_2.png) [@artelk](https://discuss.elastic.co/u/artelk)\
**Post date:** [August 29, 2017, 9:52am UTC](https://discuss.elastic.co/t/are-objects-searchable-after-updates/98562/6 "2017-08-29T09:52:59Z")

</div>

Writer will wait for its changes to be available for searches (specifying the refresh option).  
Reader should wait for writer and shouldn't request Elasticsearch until writer completes its work (including waiting until the changes are available for searches). Otherwise it is possible that the request will return nothing, even if the predicate is True for both values (old and new one). Please correct me if I'm wrong.

Reader and writer can be on different machines. So this synchronization requires some kind of distributed lock, right?  
That would be great if there is some better alternative.

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [August 29, 2017, 10:00am UTC](https://discuss.elastic.co/t/are-objects-searchable-after-updates/98562/7 "2017-08-29T10:00:43Z")

</div>

It's not a global lock, there is no such thing in Elasticsearch.

Refreshes happen, by default, every second.

---

<div class="post-metadata">

**Author:** ![artelk](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/artelk/32/45644_2.png) [@artelk](https://discuss.elastic.co/u/artelk)\
**Post date:** [August 29, 2017, 10:09am UTC](https://discuss.elastic.co/t/are-objects-searchable-after-updates/98562/8 "2017-08-29T10:09:20Z")

</div>

I mean I need to use an explicit global distributed lock in the client code to synchronize reader and writer to avoid the situation with disappearing objects on reader side. Without synchronization if the reader periodically requests for the object by that predicate it is possible that some of the requests can return nothing and on the next request the object appears again.

---

<div class="post-metadata">

**Author:** ![artelk](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/artelk/32/45644_2.png) [@artelk](https://discuss.elastic.co/u/artelk)\
**Post date:** [August 29, 2017, 10:37am UTC](https://discuss.elastic.co/t/are-objects-searchable-after-updates/98562/9 "2017-08-29T10:37:43Z")

</div>

That would be the best if Elasticsearch returned an old state of the object until it is refreshed and new state is indexed.

---

<div class="post-metadata">

**Author:** ![artelk](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/artelk/32/45644_2.png) [@artelk](https://discuss.elastic.co/u/artelk)\
**Post date:** [August 30, 2017, 8:01am UTC](https://discuss.elastic.co/t/are-objects-searchable-after-updates/98562/10 "2017-08-30T08:01:09Z")

</div>

A few more questions:

If some other property Y is changed will the object disappear from searching for some time?

Lets assume you established a parent/child relationship. A new child is added. Can it hide the parent and/or other children from readers for some time?

---

<div class="post-metadata">

**Author:** ![artelk](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/artelk/32/45644_2.png) [@artelk](https://discuss.elastic.co/u/artelk)\
**Post date:** [September 1, 2017, 10:32am UTC](https://discuss.elastic.co/t/are-objects-searchable-after-updates/98562/11 "2017-09-01T10:32:23Z")

</div>

Guys, could you please answer. This is important for our project.

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [September 1, 2017, 10:38am UTC](https://discuss.elastic.co/t/are-objects-searchable-after-updates/98562/12 "2017-09-01T10:38:01Z")

</div>

If you'd like SLA based response times we will happily put you in touch with someone from our sales team. Otherwise please have patience and we will answer you when we can.

As for me, it's Friday night so hopefully someone else will pop in in the meantime 🙂

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [September 7, 2017, 8:02am UTC](https://discuss.elastic.co/t/are-objects-searchable-after-updates/98562/13 "2017-09-07T08:02:00Z")

</div>

> [@artelk](#):
>
> A new child is added. Can it hide the parent and/or other children from readers for some time?

No it won't.

---

<div class="post-metadata">

**Author:** ![artelk](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/artelk/32/45644_2.png) [@artelk](https://discuss.elastic.co/u/artelk)\
**Post date:** [September 8, 2017, 9:12am UTC](https://discuss.elastic.co/t/are-objects-searchable-after-updates/98562/14 "2017-09-08T09:12:29Z")

</div>

That's great, thank you Mark!  
Do you know if it is planned to change the Elasticsearch behavior regarding the changes of the same object? To return old state until a new one's indexing completes. I believe this is the only step left to make it usable as a real nosql storage (not only as a great searching tool).

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [September 8, 2017, 9:13am UTC](https://discuss.elastic.co/t/are-objects-searchable-after-updates/98562/15 "2017-09-08T09:13:42Z")

</div>

> [@artelk](#):
>
> To return old state until a new one's indexing completes

That's the only thing it can do.

---

<div class="post-metadata">

**Author:** ![artelk](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/artelk/32/45644_2.png) [@artelk](https://discuss.elastic.co/u/artelk)\
**Post date:** [September 8, 2017, 9:18am UTC](https://discuss.elastic.co/t/are-objects-searchable-after-updates/98562/16 "2017-09-08T09:18:48Z")

</div>

What do you mean? The object won't be hidden from searches in the middle of updating the object properties (even if it is searched by modifying property)?

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [September 8, 2017, 9:21am UTC](https://discuss.elastic.co/t/are-objects-searchable-after-updates/98562/17 "2017-09-08T09:21:31Z")

</div>

The _only_ time that can happen is if you make a request to a shard that is applying the change at the **exact same time**.

The chances of that, while not null, aren't that likely.

---

<div class="post-metadata">

**Author:** ![artelk](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/artelk/32/45644_2.png) [@artelk](https://discuss.elastic.co/u/artelk)\
**Post date:** [September 8, 2017, 9:48am UTC](https://discuss.elastic.co/t/are-objects-searchable-after-updates/98562/18 "2017-09-08T09:48:06Z")

</div>

We have ~million documents in the storage. About 10% of them are updated during the day at arbitrary times.  
Also there are several systems that search for objects by some predicates (they use scroll to fetch all the objects for which the predicate is true, then produce some reports etc.). They can do it in parallel with updates, the updates and searches are not synchronized.  
The question is if it is possible that some of the objects can disappear in the report just because it is currently updating (even if for the old state of the object and for the new one the predicate is true).

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [September 8, 2017, 10:07am UTC](https://discuss.elastic.co/t/are-objects-searchable-after-updates/98562/19 "2017-09-08T10:07:47Z")

</div>

It's a possibility.

---

<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:** [October 6, 2017, 10:08am UTC](https://discuss.elastic.co/t/are-objects-searchable-after-updates/98562/20 "2017-10-06T10:08:04Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
