elasticsearch 弹性搜索查询两个值-术语和范围?
我正在尝试执行一个查询,其中需要基于两个值的文档—名称(字符串)和百分比(数字)。 例如,我希望这些文档包含“accounter.location.countries.name”=“US”和“accounter.location.countries.percentage”>60。所以我想要一个有对象{“name”:“US”,“percentage”:“65”} 这里,“acquisition.location.countries”是一个具有两个属性的对象数组—{“name”,“percentage”}。 以下是一个示例文档:elasticsearch 弹性搜索查询两个值-术语和范围?,elasticsearch,kibana,elasticsearch,Kibana,我正在尝试执行一个查询,其中需要基于两个值的文档—名称(字符串)和百分比(数字)。 例如,我希望这些文档包含“accounter.location.countries.name”=“US”和“accounter.location.countries.percentage”>60。所以我想要一个有对象{“name”:“US”,“percentage”:“65”} 这里,“acquisition.location.countries”是一个具有两个属性的对象数组—{“name”,“percentag
"location": {
"countries": [
{
"name": "CA",
"percentage": 4
},
{
"name": "GB",
"percentage": 5
},
{
"name": "JP",
"percentage": 8
},
{
"name": "US",
"percentage": 60
}
]}
这是一个我尝试过的查询,但它抛出了一个错误:“[和]查询格式不正确,查询名称后没有start\u对象”
我是弹性搜索新手,知识非常有限。有人能帮忙吗?据我所知,有几个账户的查询被“破坏”:
范围
和术语
在名称
和百分比
字段上的过滤器是混合的受众.位置.国家/地区应为“”
GET opensponsorship/_search
{
"query": {
"bool": {
"filter": [
{
"term": {
"isPublic": true
}
},
{
"term": {
"isDeleted": false
}
},
{
"term": {
"audience.location.countries.name": "US"
}
},
{
"range": {
"audience.location.countries.percentage": {
"gt": 59
}
}
}
]
}
},
"size": "60",
"from": 0,
"sort": [
{
"followers": {
"order": "desc"
}
}
]
}
关于问题3,我建议您阅读elasticsearch。
简言之,如果acquisition.location.countries
不是嵌套对象,则由于对象的弹性“展平”,将产生“假阳性”结果。
要解决此问题,您需要1)在映射中使访问群体.location.countries
成为嵌套对象类型,以及2)以以下方式将配置
术语过滤器与嵌套查询包装在一起:
GET opensponsorship/_search
{
"query": {
"bool": {
"filter": [
{
"term": {
"isPublic": true
}
},
{
"term": {
"isDeleted": false
}
},
{
"nested": {
"path": "audience.location.countries",
"query": {
"bool": {
"filter": [
{
"term": {
"audience.location.countries.name": "US"
}
},
{
"range": {
"audience.location.countries.percentage": {
"gt": 59
}
}
}
]
}
}
}
}
]
}
},
"size": "60",
"from": 0,
"sort": [
{
"followers": {
"order": "desc"
}
}
]
}
希望这有帮助。祝你好运 据我所知,查询在多个帐户上被“破坏”:
范围
和术语
在名称
和百分比
字段上的过滤器是混合的受众.位置.国家/地区应为“”
GET opensponsorship/_search
{
"query": {
"bool": {
"filter": [
{
"term": {
"isPublic": true
}
},
{
"term": {
"isDeleted": false
}
},
{
"term": {
"audience.location.countries.name": "US"
}
},
{
"range": {
"audience.location.countries.percentage": {
"gt": 59
}
}
}
]
}
},
"size": "60",
"from": 0,
"sort": [
{
"followers": {
"order": "desc"
}
}
]
}
关于问题3,我建议您阅读elasticsearch。
简言之,如果acquisition.location.countries
不是嵌套对象,则由于对象的弹性“展平”,将产生“假阳性”结果。
要解决此问题,您需要1)在映射中使访问群体.location.countries
成为嵌套对象类型,以及2)以以下方式将配置
术语过滤器与嵌套查询包装在一起:
GET opensponsorship/_search
{
"query": {
"bool": {
"filter": [
{
"term": {
"isPublic": true
}
},
{
"term": {
"isDeleted": false
}
},
{
"nested": {
"path": "audience.location.countries",
"query": {
"bool": {
"filter": [
{
"term": {
"audience.location.countries.name": "US"
}
},
{
"range": {
"audience.location.countries.percentage": {
"gt": 59
}
}
}
]
}
}
}
}
]
}
},
"size": "60",
"from": 0,
"sort": [
{
"followers": {
"order": "desc"
}
}
]
}
希望这有帮助。祝你好运