我正在尝试使用索引上的过滤器进行查询,但是当我尝试对映射中的任何属性进行过滤时,查询都不会返回结果。
以下是查询,如果仅使用geo_distance部分运行,则会得到结果。我想使用映射中的属性之一过滤结果(在这种情况下为等级,但可以是城市,州ecc)。 查询是通过ElasticBuild库(v 52.0)中的QueryBuilder用Java生成的。但是现在,我试图了解如何构建有效的查询并通过CURL执行。
{
"query": {
"bool": {
"filter": [
{
"geo_distance": {
"geometry.coordinates": [
12.3232,
12.2323
],
"distance": 200000,
"distance_type": "plane",
"validation_method": "STRICT",
"ignore_unmapped": false,
"boost": 1
}
},
{
"bool": {
"must": [
{
"terms": {
"rating": [
"0"
],
"boost": 1
}
}
],
"adjust_pure_negative": true,
"boost": 1
}
}
],
"adjust_pure_negative": true,
"boost": 1
}
}
}
如果我对邮政编码或ID运行查询过滤,则可以正常运行。 例如这样的查询:
{"query":{"bool":{"filter":{"term":{"zipCode":"111111"}}}}}
我的映射的一个片段是这个
{
"my_index": {
"mappings": {
"poielement": {
"dynamic_templates": [
{
"suggestions": {
"match": "suggest_*",
"mapping": {
"analyzer": "my_analyzer",
"copy_to": "auto_suggest",
"search_analyzer": "my_analyzer",
"store": true,
"type": "text"
}
}
},
{
"integers": {
"match_mapping_type": "long",
"mapping": {
"type": "text"
}
}
},
{
"geopoint": {
"match": "coordinates",
"mapping": {
"type": "geo_point"
}
}
},
{
"property": {
"match": "*",
"mapping": {
"analyzer": "my_analyzer",
"search_analyzer": "my_analyzer"
}
}
}
],
"date_detection": false,
"numeric_detection": false,
"properties": {
"city": {
"type": "text",
"analyzer": "my_analyzer"
},
"country": {
"type": "text",
"analyzer": "my_analyzer"
},
"geometry": {
"properties": {
"coordinates": {
"type": "geo_point"
},
"type": {
"type": "text",
"analyzer": "my_analyzer"
}
}
},
"id": {
"type": "text"
},
"name": {
"type": "keyword"
},
"rating": {
"type": "text"
},
"total_rate": {
"type": "text",
"analyzer": "my_analyzer"
},
"type": {
"type": "text",
"analyzer": "my_analyzer"
},
"zipCode": {
"type": "text"
}
}
}
}
}
}
当我通过http://elasticsearchpat/my_index/_search检索数据时,数据看起来像这样
{
"took": 1,
"timed_out": false,
"_shards": {
"total": 4,
"successful": 4,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 7517,
"max_score": 1,
"hits": [
{
"_index": "my_index",
"_type": "poielement",
"_id": "58768",
"_score": 1,
"_source": {
"zipCode": 111111,
"country": "USA",
"city": "Portland",
"rating": 0,
"type": "",
"id": 123,
"geometry": {
"coordinates": [
12.205061,
12.490463
],
"type": "Point"
}
}
}
]
}
}
我将非常感谢您的帮助。
谢谢
答案 0 :(得分:0)
尝试使用此查询
$foo = $bar
echo $foo