[英]Multi Filter of Nested Elasticsearch Data
I have a data structure that looks like this: 我有一个看起来像这样的数据结构:
"dictionaryProximities": [
{
"proximity": 0.32427,
"topicDictionaryName": "Electrical",
},
{
"proximity": 0.32141,
"topicDictionaryName": "Indoor Air Quality",
},
{
"proximity": 0.7321,
"topicDictionaryName": "Smart Home Technology",
},
I want to create a filter/query that will return all files where the proximity of "Smart Home Technology" is greater than a value, say 0.7. 我想创建一个过滤器/查询,该过滤器/查询将返回“ Smart Home Technology”的接近度大于某个值(例如0.7)的所有文件。
Right now I have the query: 现在我有查询:
{
"query": {
"nested": {
"path": "dictionaryProximities",
"query": {
"match": {
"dictionaryProximities.topicDictionaryName": {
"query": "Smart Home Technology",
"type": "phrase"
}
}
}
}
}
}
stacked with the query: 与查询堆叠在一起:
{
"query": {
"nested": {
"path": "dictionaryProximities",
"query": {
"range": {
"dictionaryProximities.proximity": {
"gte": 0.7,
"lt": 1
}
}
}
}
}
}
This returns all files with proximity above 0.7 and contain the name Smart Home Technology. 这将返回所有接近度大于0.7的文件,并包含名称Smart Home Technology。 This is very different from what I want, which is all files that have a proximity above 0.7 ONLY for Smart Home Technology.
这与我想要的有很大的不同,后者是智能家居技术的所有文件的相近度仅在0.7以上。
My question is, is there a way to combine these two queries in a way that achieves the result I want? 我的问题是,有没有一种方法可以将这两个查询组合起来以达到我想要的结果? Is this task even possible since proximity and Name are nested in the same level?
由于接近度和名称嵌套在同一级别,该任务甚至有可能实现吗? Any help would be super appreciated.
任何帮助将不胜感激。
Figured it out. 弄清楚了。
{
"query": {
"nested": {
"path": "dictionaryProximities",
"query": {
"bool": {
"must": [
{"match": {"dictionaryProximities.topicDictionaryName": "Windows and Doors"}},
{"range": {"dictionaryProximities.proximity": {"gt": "0.6", "lt": "1.0"}}}
]
}
}
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.