Is it possible to query and receive result when only part of the entity is indexed?


(Mysurf Mail) #1

My entity has the following fields -
Id, Name, Format, some other fields.
I send an entity to the ES.

I am querying elasticsearch - filtering by one entity property - name.
I get the entity in the result.

A split second later I query by other property - e.g. format.
I don't get my entity.

Then I sleep for three seconds.
I request the second query again (filter by format ).
I do get my entity.

Is it possible to query and receive result when only a part of the entity is indexed
(- and some other part will be indexed soon )?

(I know that when I add an attribute to a mapping I have to reindex the entity because the weights have to be updates. Therefor I don't understand querying partial index )


(Magnus Bäck) #2

You can assume that all fields of a document are indexed at the same time. The reason for the behavior you're seeing is that the underlying Lucene index hadn't been refreshed by the time you make the first query, but by the time of the second query the periodic refresh had taken place and you get the result you wanted. If you want to have documents immediately queryable you can issue a manual refresh and the index operation.


(Mark Walkom) #3

This is why ES is near-realtime.

Also, be careful calling a refresh every time you index a document, it can be an expensive request.


(Mysurf Mail) #4

Oh, Great.

Actually, I am writing this code in my automation tests.
I post my entity. It is then sent to ElasticSearch.

I designed it so that instead of going on with my test - I poll ES by one field until my entity is reachable.
How can I know when my elasticSearch has fully indexed my entity and it is fully searchable by all fields.


(Mysurf Mail) #5

But, my first query succeeds.
That is the problem I am describing.

filter by one property is working.
filter by the second property is not working.
sleep (3sec)
filter by the second property does work.


(Magnus Bäck) #6

But, my first query succeeds.
That is the problem I am describing.

Okay, I can't explain that. Doesn't really matter though; if you want to make sure that a newly inserted document is searchable you need to refresh the index.


(system) #7