使用Elasticsearch查询字段的所有唯一值 [英] Query all unique values of a field with Elasticsearch
问题描述
如何使用弹性搜索搜索给定字段的所有唯一值?
How do I search for all unique values of a given field with Elasticsearch?
我有一种类似从作者选择full_name
,所以我可以在表单上的用户显示列表。
I have such a kind of query like select full_name from authors
, so I can display the list to the users on a form.
推荐答案
您可以在full_name上条款方面 '领域。但是为了正确地做到这一点,您需要确保在编制索引时不会对其进行标记,否则该方面的每个条目都将是一个不同的术语,即字段内容的一部分。您最有可能需要在映射中将其配置为not_analyzed。如果您还在搜索它,并且您仍然想要标记它,您可以使用多字段。
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.
您还需要考虑到,根据作为full_name字段一部分的唯一字词数,这个操作可能是昂贵的,需要相当多的记忆。
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.
这篇关于使用Elasticsearch查询字段的所有唯一值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!