Query all unique values of a field with Elasticsearch

前端 未结 5 937
陌清茗
陌清茗 2020-12-29 19:52

How do I search for all unique values of a given field with Elasticsearch?

I have such a kind of query like select full_name from authors

5条回答
  •  借酒劲吻你
    2020-12-29 20:19

    You could make a terms facet on your 'full_name' field. But in order to do that properly you need to make sure you're not tokenizing it while indexing, otherwise every entry in the facet will be a different term that is part of the field content. You most likely need to configure it as 'not_analyzed' in your mapping. If you are also searching on it and you still want to tokenize it you can just index it in two different ways using multi field.

    You also need to take into account that depending on the number of unique terms that are part of the full_name field, this operation can be expensive and require quite some memory.

提交回复
热议问题