弹性搜索 - 显示数组的所有不同值 [英] Elastic Search - display all distinct values of an array
问题描述
主题:[p] 科学研究,数值分析,艺术史]
我想查询此字段并检索具有频率计数的类别的全名。到目前为止,我尝试的方面是:
查询:{
match_all:{}
},
facets:{
tag:{
terms:{
field:subject}
}
}
不按预期工作,因为它将我的主题字段分成标记,并将我的最多频繁的戒烟。如何获得已分析字段的计数的完整条目,而不仅仅是前10名?谢谢!
我将使用多字段
定义您的映射像这样 -
{
.....
....
。 ...
subject:{
type:multi_field,
store:yes,
fields:{
分析:{
type:string,
analyzer:standard
},
notanalyzed:{
type :string,
index:not_analyzed
}
}
}
然后,我将在 notanalyzed
字段上执行您的刻板,如下所示 -
查询:{
match_all:{}
},
facets:{
tag
条款:{
field:subject.notanalyzed,
size:50
}
}
}
For a field mapped as string I have stored list of strings in the ES index, for ex:
subject: ["Scientific Research", "Numerical Analysis", "History of Art"]
I would like to query this field and retrieve the full names of categories with their frequency count. What I tried so far with facets:
"query":{
"match_all": {}
},
"facets":{
"tag":{
"terms":{
"field":"subject"}
}
}
is not working as expected because it splits my subject fields into tokens and returns me the top most frequent stopwords. How can I get full entries ordered by counts for an analyzed field, and not only the top 10, if possible? Thanks!
I would use a multi-field
define your mapping like so -
{
.....
....
.....
"subject": {
"type": "multi_field",
"store": "yes",
"fields": {
"analyzed": {
"type": "string",
"analyzer": "standard"
},
"notanalyzed": {
"type": "string",
"index": "not_analyzed"
}
}
}
Then I would carry out your faceting on the notanalyzed
field like so -
"query":{
"match_all": {}
},
"facets":{
"tag":{
"terms":{
"field":"subject.notanalyzed",
"size": 50
}
}
}
这篇关于弹性搜索 - 显示数组的所有不同值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!