我有以下索引映射:
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"
}
}
]
}
}
}
关于elasticsearch - 在Elasticsearch中是否可以按地理形状类型进行搜索,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59156781/