找不到地理点字段位置springframework data elasticsearch

jv4diomz  于 2021-06-13  发布在  ElasticSearch
关注(0)|答案(1)|浏览(344)

找不到地理点字段位置。位置字段在Map时应该有geo_点,但得到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;
.
.

}
测试索引.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();

Map:(不需要)http://localhost:9200/testindex/\uMap

"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}

预期Map

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

xe55xuns1#

当我使用索引名geopoint test定义如上所述的实体属性并执行Map创建代码(在应用程序启动时也会执行该代码)时,我得到以下Map:

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

显示的Map有两个不同之处:
这个 location 属性Map正确
这个 latitude 以及 longitude 属性不会写入Map,因为它们不会用注解进行注解 @Field 剩下的就是自动绘图了。
您显示的Map是将自动创建的Map。
您使用的是哪个版本的spring data elasticsearch?
编辑12.12.2020:
使用spring data elasticsearch 4.0.2并将两者相加 @Field 注解到 latitude 以及 longitude 属性时,索引的初始设置和显式编写Map的代码都会生成此Map:

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

相关问题