gpt4 book ai didi

elasticsearch - 范围过滤器不适用于 “gt”运算符,但适用于 “lt”

转载 作者:行者123 更新时间:2023-12-03 01:38:00 26 4
gpt4 key购买 nike

我正在使用 Elasticsearch 为我的文档建立索引,并希望根据特定属性过滤文档。这是我的代码:

filter.push({
range: {"audience.ethnicity.asian" : { gt: 50 } }
})

它不适用于gt运算符(发回不一致的结果),但适用于lt运算符
filter.push({
range: {"audience.ethnicity.asian" : { lt: 50 } }
})

这出奇地起作用。我已经仔细检查过,属性值是一个整数。我尝试了许多不同的方法,但似乎无法弄清我想念的是什么。
对应:
  "audience": {
"properties": {
"age": {
"properties": {
"13-17": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"18-24": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"25-34": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"35-44": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"45-64": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"eighteen": {
"type": "long"
},
"fortyfive": {
"type": "long"
},
"thirteen": {
"type": "long"
},
"thirtyfive": {
"type": "long"
},
"twentyfive": {
"type": "long"
}
}
},
"ages": {
"properties": {
"13-17": {
"type": "float"
},
"18-24": {
"type": "float"
},
"25-34": {
"type": "float"
},
"35-44": {
"type": "float"
},
"45-64": {
"type": "float"
}
}
},
"ethnicity": {
"properties": {
"African American": {
"type": "float"
},
"Asian": {
"type": "float"
},
"Hispanic": {
"type": "float"
},
"White / Caucasian": {
"type": "float"
},
"african": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"asian": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"hispanic": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"white": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
},
"gender": {
"properties": {
"female": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"male": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
},
"genders": {
"properties": {
"FEMALE": {
"type": "float"
},
"MALE": {
"type": "float"
}
}
},
"gendersPerAge": {
"properties": {
"13-17": {
"properties": {
"FEMALE": {
"type": "float"
},
"MALE": {
"type": "float"
}
}
},
"18-24": {
"properties": {
"FEMALE": {
"type": "float"
},
"MALE": {
"type": "float"
}
}
},
"25-34": {
"properties": {
"FEMALE": {
"type": "float"
},
"MALE": {
"type": "float"
}
}
},
"35-44": {
"properties": {
"FEMALE": {
"type": "float"
},
"MALE": {
"type": "float"
}
}
},
"45-64": {
"properties": {
"FEMALE": {
"type": "float"
},
"MALE": {
"type": "float"
}
}
}
}
}
}
} "audience": {
"properties": {
"age": {
"properties": {
"13-17": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"18-24": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"25-34": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"35-44": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"45-64": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"eighteen": {
"type": "long"
},
"fortyfive": {
"type": "long"
},
"thirteen": {
"type": "long"
},
"thirtyfive": {
"type": "long"
},
"twentyfive": {
"type": "long"
}
}
},
"ages": {
"properties": {
"13-17": {
"type": "float"
},
"18-24": {
"type": "float"
},
"25-34": {
"type": "float"
},
"35-44": {
"type": "float"
},
"45-64": {
"type": "float"
}
}
},
"ethnicity": {
"properties": {
"African American": {
"type": "float"
},
"Asian": {
"type": "float"
},
"Hispanic": {
"type": "float"
},
"White / Caucasian": {
"type": "float"
},
"african": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"asian": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"hispanic": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"white": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
},
"gender": {
"properties": {
"female": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"male": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
},
"genders": {
"properties": {
"FEMALE": {
"type": "float"
},
"MALE": {
"type": "float"
}
}
},
"gendersPerAge": {
"properties": {
"13-17": {
"properties": {
"FEMALE": {
"type": "float"
},
"MALE": {
"type": "float"
}
}
},
"18-24": {
"properties": {
"FEMALE": {
"type": "float"
},
"MALE": {
"type": "float"
}
}
},
"25-34": {
"properties": {
"FEMALE": {
"type": "float"
},
"MALE": {
"type": "float"
}
}
},
"35-44": {
"properties": {
"FEMALE": {
"type": "float"
},
"MALE": {
"type": "float"
}
}
},
"45-64": {
"properties": {
"FEMALE": {
"type": "float"
},
"MALE": {
"type": "float"
}
}
}
}
}
}
}

最佳答案

在您的映射中,audience.ethnicity.asian字段为文本类型,因此范围查询正在执行词法范围比较,而不是数值范围比较

在数字上> 123> 50,但是在词法上123 <50,因为ASCII字符1排在5之前,这正是您在这里遇到的问题。

我不确定是否可以使用audience.ethnicity.Asian字段,该字段是浮点型的。如果不是,则需要将audience.ethnicity.asian的映射更改为数字类型(integerfloat等),然后重新索引数据。

关于elasticsearch - 范围过滤器不适用于 “gt”运算符,但适用于 “lt”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50825828/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com