Elasticsearch "failed to find geo_point field [location]" 当该字段存在映射时
Elasticsearch "failed to find geo_point field [location]" when the mapping is there for that field
我有一个具有以下映射的索引:
{
"mappings":{
"my_stuff_type":{
"properties":{
"location": {
"type": "geo_point",
"null_value": -1
}
}
}
}
}
我必须使用 属性 null_value
因为我的一些文档没有关于它们位置的信息 (latitude/longitude),但我仍然想按距离搜索在一个位置上,cf。这里:https://www.elastic.co/guide/en/elasticsearch/reference/current/null-value.html
检查索引映射详细信息时,我可以验证地理映射是否存在:
curl -XGET http://localhost:9200/my_stuff_index/_mapping | jq '.my_stuff_index.mappings.my_stuff_type.properties.location'
{
"properties": {
"lat": {
"type": "float"
},
"lon": {
"type": "float"
}
}
}
然而,当尝试使用地理距离过滤器(参见 https://www.elastic.co/guide/en/elasticsearch/guide/current/geo-distance.html)搜索该索引上的文档时,我看到了:
curl -XPOST http://localhost:9200/my_stuff_index/_search -d'
{
"query": {
"bool": {
"filter": {
"geo_distance": {
"location": {
"lat": <PUT_LATITUDE_FLOAT_HERE>,
"lon": <PUT_LONGITUDE_FLOAT_HERE>
},
"distance": "200m"
}
}
}
}
}' | jq
{
"error": {
"root_cause": [
{
"type": "query_shard_exception",
"reason": "failed to find geo_point field [location]",
"index_uuid": "mO94yEsHQseQDFPkHjM6tA",
"index": "my_stuff_index"
}
],
"type": "search_phase_execution_exception",
"reason": "all shards failed",
"phase": "query",
"grouped": true,
"failed_shards": [
{
"shard": 0,
"index": "my_stuff_index",
"node": "MDueSn31TS2z0Lamo64zbw",
"reason": {
"type": "query_shard_exception",
"reason": "failed to find geo_point field [location]",
"index_uuid": "mO94yEsHQseQDFPkHjM6tA",
"index": "my_stuff_index"
}
}
],
"caused_by": {
"type": "query_shard_exception",
"reason": "failed to find geo_point field [location]",
"index_uuid": "mO94yEsHQseQDFPkHjM6tA",
"index": "my_stuff_index"
}
},
"status": 400
}
我认为 null_value
属性 应该允许我在没有 location
归档的情况下插入文档,同时我应该能够在同一个 "optional"字段。
为什么我无法过滤 "optional" 字段?我该怎么做?
编辑:
要在从命令行执行 curl
/jq
操作之前,使用 python 运行 以下代码片段重现此问题。
python代码依赖于:pip install elasticsearch==5.4.0
.
from elasticsearch import Elasticsearch
from elasticsearch import helpers
my_docs = [
{"xyz": "foo", "location": {"lat": 0.0, "lon": 0.0}},
{"xyz": "bar", "location": {"lat": 50.0, "lon": 50.0}}
]
es = Elasticsearch([{'host': 'localhost', 'port': 9200}])
index_mapping = '''
{
"mappings":{
"my_stuff_type":{
"properties":{
"location": {
"type": "geo_point",
"null_value": -1.0
}
}
}
}
}'''
es.indices.create(index='my_stuff_index', ignore=400, body=index_mapping)
helpers.bulk(es, my_docs, index='my_stuff_index', doc_type='my_stuff_type')
正如@Val 所说,您应该更改您的映射。如果这样定义位置字段:
"location": {
"type": "geo_point"
}
您可以将 lan
和 lon
索引为两个不同的子字段 - 无需在映射中声明它们,如我所示 - 如文档中所述 - look here
我有一个具有以下映射的索引:
{
"mappings":{
"my_stuff_type":{
"properties":{
"location": {
"type": "geo_point",
"null_value": -1
}
}
}
}
}
我必须使用 属性 null_value
因为我的一些文档没有关于它们位置的信息 (latitude/longitude),但我仍然想按距离搜索在一个位置上,cf。这里:https://www.elastic.co/guide/en/elasticsearch/reference/current/null-value.html
检查索引映射详细信息时,我可以验证地理映射是否存在:
curl -XGET http://localhost:9200/my_stuff_index/_mapping | jq '.my_stuff_index.mappings.my_stuff_type.properties.location'
{
"properties": {
"lat": {
"type": "float"
},
"lon": {
"type": "float"
}
}
}
然而,当尝试使用地理距离过滤器(参见 https://www.elastic.co/guide/en/elasticsearch/guide/current/geo-distance.html)搜索该索引上的文档时,我看到了:
curl -XPOST http://localhost:9200/my_stuff_index/_search -d'
{
"query": {
"bool": {
"filter": {
"geo_distance": {
"location": {
"lat": <PUT_LATITUDE_FLOAT_HERE>,
"lon": <PUT_LONGITUDE_FLOAT_HERE>
},
"distance": "200m"
}
}
}
}
}' | jq
{
"error": {
"root_cause": [
{
"type": "query_shard_exception",
"reason": "failed to find geo_point field [location]",
"index_uuid": "mO94yEsHQseQDFPkHjM6tA",
"index": "my_stuff_index"
}
],
"type": "search_phase_execution_exception",
"reason": "all shards failed",
"phase": "query",
"grouped": true,
"failed_shards": [
{
"shard": 0,
"index": "my_stuff_index",
"node": "MDueSn31TS2z0Lamo64zbw",
"reason": {
"type": "query_shard_exception",
"reason": "failed to find geo_point field [location]",
"index_uuid": "mO94yEsHQseQDFPkHjM6tA",
"index": "my_stuff_index"
}
}
],
"caused_by": {
"type": "query_shard_exception",
"reason": "failed to find geo_point field [location]",
"index_uuid": "mO94yEsHQseQDFPkHjM6tA",
"index": "my_stuff_index"
}
},
"status": 400
}
我认为 null_value
属性 应该允许我在没有 location
归档的情况下插入文档,同时我应该能够在同一个 "optional"字段。
为什么我无法过滤 "optional" 字段?我该怎么做?
编辑:
要在从命令行执行 curl
/jq
操作之前,使用 python 运行 以下代码片段重现此问题。
python代码依赖于:pip install elasticsearch==5.4.0
.
from elasticsearch import Elasticsearch
from elasticsearch import helpers
my_docs = [
{"xyz": "foo", "location": {"lat": 0.0, "lon": 0.0}},
{"xyz": "bar", "location": {"lat": 50.0, "lon": 50.0}}
]
es = Elasticsearch([{'host': 'localhost', 'port': 9200}])
index_mapping = '''
{
"mappings":{
"my_stuff_type":{
"properties":{
"location": {
"type": "geo_point",
"null_value": -1.0
}
}
}
}
}'''
es.indices.create(index='my_stuff_index', ignore=400, body=index_mapping)
helpers.bulk(es, my_docs, index='my_stuff_index', doc_type='my_stuff_type')
正如@Val 所说,您应该更改您的映射。如果这样定义位置字段:
"location": {
"type": "geo_point"
}
您可以将 lan
和 lon
索引为两个不同的子字段 - 无需在映射中声明它们,如我所示 - 如文档中所述 - look here