Very simple question. I have an ElasticSearch index with a text field. How do I get the list of all the words indexed for that field? Is there any simple method?
I'm working in python with elasticsearch library.
Very simple question. I have an ElasticSearch index with a text field. How do I get the list of all the words indexed for that field? Is there any simple method?
I'm working in python with elasticsearch library.
⚠️ Warning
Solution
To be able to do so, the Elasticsearch first needs to load all that words into memory, which is disabled by default for text fields (see FieldData mapping parameter for more info).
Assuming that the field data is enable on your index, you can get the unique terms list, sorted by their frequence using below serach query:
unless enabling the fieldData, you will encounter such a below error:
For a single document ...
If you only need to fetch such a list of indexed terms for a single document, you can simply use the _termsvector API, while you don't need to enable field data anymore.