我具有以下索引映射:
PUT testing/_mapping
{
"properties": {
"location": {
"type": "geo_shape"
}
}
}
我索引了两个文件:
PUT testing/_doc/1
{
"location": {
"type": "point",
"coordinates": [13.400544, 52.530286]
}
}
PUT testing/_doc/2
{
"location": {
"type" : "linestring",
"coordinates" : [[-77.03653, 38.897676], [-77.009051, 38.889939]]
}
}
现在,我想按其地理形状类型查找文档,例如仅文档为type=point
(文档1)。在Elasticsearch中可以吗?我尝试了以下搜索,但始终返回0个结果。
GET testing/_search
{
"query":{
"bool": {
"must": [
{
"term": {
"location.type": {
"value": "point"
}
}
}
]
}
}
}
我正在使用Elasticsearch 7.2.1。
您无法通过location.type
字段进行搜索,无法搜索。
我建议您也将形状的类型索引到另一个字段中,如下所示:
PUT testing/_doc/1
{
"location": {
"type": "point",
"coordinates": [13.400544, 52.530286]
},
"type": "point"
}
PUT testing/_doc/2
{
"location": {
"type" : "linestring",
"coordinates" : [[-77.03653, 38.897676], [-77.009051, 38.889939]]
},
"type": "linestring"
}
然后您可以像这样搜索:
GET testing/_search
{
"query":{
"bool": {
"must": [
{
"term": {
"type.keyword": "point"
}
}
]
}
}
}