【问题标题】:Failed to find geo_point field location Springframework Data Elasticsearch找不到geo_point字段位置Springframework Data Elasticsearch
【发布时间】:2020-12-09 14:13:33
【问题描述】:

未能找到 geo_point 字段位置。 location 字段在映射中应该有 geo_point,但会得到 lat、lon。

模型类:

import org.springframework.data.elasticsearch.annotations.GeoPointField;
import org.springframework.data.elasticsearch.core.geo.GeoPoint;

class EsMapping extends TestIndex{
@GeoPointField
private GeoPoint location;
@Field(type = FieldType.Double)
private double latitude;
@Field(type = FieldType.Double)
private double longitude;
.
.

}

TestIndex.java

class TestIndex{
    @Field(type = FieldType.Text)
    private String name;
    .
    .
}

测试控制器

@Autowired
private ElasticsearchOperations elasticsearchOperations;

IndexOperations esMappingIndex = 
elasticsearchOperations.indexOps(EsMapping.class);
esMappingIndex.delete();
esMappingIndex.create();
esMappingIndex.putMapping(esMappingIndex.createMapping());
esMappingIndex.refresh();

映射:(非预期) http://localhost:9200/testindex/_mapping

"location": {
                "properties": {
                    "lat": {
                        "type": "float"
                    },
                    "lon": {
                        "type": "float"
                    }
                }
            },
"latitude": {
                "type": "float"
            },
"longitude": {
                "type": "float"
            },

错误:

    {"error":{"root_cause":[{"type":"query_shard_exception","reason":"failed to find geo_point field [location] ","index_uuid":"QLCjshecRNqDMXtkrtbF9g","index":"testindex"}],"type":"search_phase_execution_exception","reason":"all shards failed","phase":"query","grouped":true,"failed_shards":[{"shard":0,"index":"testindex","node":"jCKzz88BQXeL3wzyX6c8lQ","reason":{"type":"query_shard_exception","reason":"failed to find geo_point field [location]","index_uuid":"QLCjshecRNqDMXtkrtbF9g","index":"testindex"}}]},"status":400}

预期映射

"location": {
                "type": "geo_point"
            },
"latitude": {
                "type": "double"
            },
"longitude": {
                "type": "double"
            },

【问题讨论】:

  • 您能否提供完整的实体定义和发生此错误时的更多上下文?
  • @P.J.Meisch 感谢您的回复,我已经添加了预期的映射和控制器类代码。

标签: elasticsearch spring-data-elasticsearch


【解决方案1】:

当我像上面那样定义实体属性时 - 使用索引名称 geopoint-test - 并执行映射创建代码(在应用程序启动时也会执行),我得到以下映射:

{
    "geopoint-test": {
        "mappings": {
            "properties": {
                "location": {
                    "type": "geo_point"
                }
            }
        }
    }
}

您显示的映射有两个不同之处:

  1. location 属性映射正确
  2. latitudelongitude 属性未写入映射,因为它们未使用 @Field 进行注释,因此留作自动映射。

您显示的映射是自动创建的。

您使用的是哪个版本的 Spring Data Elasticsearch?

编辑 12.12.2020:

使用 Spring Data Elasticsearch 4.0.2 并将两个 @Field 注释添加到 latitudelongitude 属性,索引的初始设置和显式编写映射的代码都会产生此映射:

{
    "properties": {
        "location": {
            "type": "geo_point"
        },
        "latitude": {
            "type": "double"
        },
        "longitude": {
            "type": "double"
        }
    }
}

【讨论】:

  • Spring Data Elasticsearch 版本:2.3.2.RELEASE
  • Spring Data Elasticsearch 从来没有 2.3.2 版本。
  • 对不起,我忘了说我在 EsMapping 中扩展了 TestIndex 类,我已经相应地更新了问题。
  • 我使用的是 Spring Data Elasticsearch 4.0.2 版本
  • 我用 4.0.2 试过这个,看我的编辑。当您尝试编写映射时,日志中是否有任何错误?
猜你喜欢
  • 2020-04-24
  • 1970-01-01
  • 1970-01-01
  • 2018-11-06
  • 1970-01-01
  • 2017-07-07
  • 1970-01-01
  • 1970-01-01
  • 2018-08-08
相关资源
最近更新 更多