Effective way to pull a unique field value from Elasticsearch 2.4?

I have a field called memberInfoId in Elasticsearch, whose value is unique in each document. I have thousands of documents in my Elasticsearch, so if I have to pull all the value of memberInfoId , terms aggregation seems to be very heavy. Any alternative to it?

If the value is unique for each document, you probably don't need to aggregate as it will only produce one count per term.
Instead just use the scroll API to fetch all the documents.

But scrolling needs multiple hits and I just want value from a field memberInfoId, not the whole document. So, do you think it's effective than terms aggregation?

As you won't be able to get back like 1m terms, yes probably it is more efficient.
You can just fetch the field you want (if you stored it explicitly in the mapping) instead of getting the _source field.

Please suggest me the ideal size I should use in the scroll API as I have thousands of documents. Do you mean to use field instead of _source ?

No idea. You need to test it and find what is the sweet spot for you.

I meant to use https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-stored-fields.html or https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-source-filtering.html

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