gpt4 book ai didi

elasticsearch - ElasticSearch-无法按距离位置排序- “status”:500

转载 作者:行者123 更新时间:2023-12-03 01:09:50 31 4
gpt4 key购买 nike

目标:搜索人物,并按照他们到我的位置的距离对他们的名字进行排序(输入纬度)
我输入许多数据,像这样:

{"index":{"_id":"1"}}
{"account_number":1,"location":[22.23, 23.12],"balance":39225,"firstname":"Amber","lastname":"Duke","age":32,"gender":"M","address":"880 Holmes Lane","employer":"Pyrami","email":"amberduke@pyrami.com","city":"Brogan","state":"IL"}
注意我输入 "location":[22.23, 23.12]的位置
为了简单起见,以下是 firstnamelastnamelocation的映射
{
"lat_lon_test2": {
"mappings": {
"properties": {
"firstname": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"lastname": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"location": {
"type": "float"
},
..........................................
这是我的审判:
GET localhost:9200/lat_lon_test2/_search?pretty

{
"query":
{
"multi_match":
{
"fields":["firstname", "lastname"],
"minimum_should_match": "80%",
"query": "Hattie"
}
}
,
"sort": [
{
"_geo_distance": {
"location": [
40.715,
-73.998 //my input location
],
"order": "asc",
"unit": "km",
"distance_type": "plane"
}
}
]
}
我得到了这个结果:
{
"error": {
"root_cause": [
{
"type": "class_cast_exception",
"reason": "class org.elasticsearch.index.fielddata.plain.SortedNumericIndexFieldData cannot be cast to class org.elasticsearch.index.fielddata.IndexGeoPointFieldData (org.elasticsearch.index.fielddata.plain.SortedNumericIndexFieldData and org.elasticsearch.index.fielddata.IndexGeoPointFieldData are in unnamed module of loader 'app')"
}
],
"type": "search_phase_execution_exception",
"reason": "all shards failed",
"phase": "query",
"grouped": true,
"failed_shards": [
{
"shard": 0,
"index": "lat_lon_test2",
"node": "oyC0x3WNRC-3ok_TzAMT2w",
"reason": {
"type": "class_cast_exception",
"reason": "class org.elasticsearch.index.fielddata.plain.SortedNumericIndexFieldData cannot be cast to class org.elasticsearch.index.fielddata.IndexGeoPointFieldData (org.elasticsearch.index.fielddata.plain.SortedNumericIndexFieldData and org.elasticsearch.index.fielddata.IndexGeoPointFieldData are in unnamed module of loader 'app')"
}
}
],
"caused_by": {
"type": "class_cast_exception",
"reason": "class org.elasticsearch.index.fielddata.plain.SortedNumericIndexFieldData cannot be cast to class org.elasticsearch.index.fielddata.IndexGeoPointFieldData (org.elasticsearch.index.fielddata.plain.SortedNumericIndexFieldData and org.elasticsearch.index.fielddata.IndexGeoPointFieldData are in unnamed module of loader 'app')",
"caused_by": {
"type": "class_cast_exception",
"reason": "class org.elasticsearch.index.fielddata.plain.SortedNumericIndexFieldData cannot be cast to class org.elasticsearch.index.fielddata.IndexGeoPointFieldData (org.elasticsearch.index.fielddata.plain.SortedNumericIndexFieldData and org.elasticsearch.index.fielddata.IndexGeoPointFieldData are in unnamed module of loader 'app')"
}
}
},
"status": 500
}
我意识到我需要将位置映射到 geopoint我这样做:
PUT localhost:9200/lat_lon_test2/_mapping

{
"properties": {
"location": {
"type": "geo_point"
}
}
}
我得到了这个结果:
{
"error": {
"root_cause": [
{
"type": "illegal_argument_exception",
"reason": "mapper [location] cannot be changed from type [float] to [geo_point]"
}
],
"type": "illegal_argument_exception",
"reason": "mapper [location] cannot be changed from type [float] to [geo_point]"
},
"status": 400
}
我的版本:7.9.3
对不起,很长的帖子

最佳答案

您将location的数据类型从float更改为geo_point,因此是异常(exception),请创建具有正确映射的新索引,并根据新的数据类型重新索引所有数据以解决此问题。
请引用有关update mapping of a field的部分以及涵盖的内容和未涵盖的内容,以及。如果需要更改其他索引中字段的映射,请使用正确的映射创建新索引,然后将数据重新索引到该索引中。

关于elasticsearch - ElasticSearch-无法按距离位置排序- “status”:500,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64674660/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com