【发布时间】:2017-04-18 20:27:02
【问题描述】:
我有不同类型的弹性搜索索引。 并且每种类型都包含一些默认字段和一些基于类型的额外字段。 每种类型都有存储纬度和经度的位置对象。 我在弹性搜索索引中的示例数据是
[{
"_index": "es_index",
"_type": "type1",
"_id": "id1",
"_source": {
"name": "name",
"type1field": "value",
"location": {
"lat": 1,
"lon": 1
}
}
}, {
"_index": "es_index",
"_type": "type2",
"_id": "id2",
"_source": {
"name": "name",
"type2field": "value",
"location": {
"lat": 1,
"lon": 1
}
}
}]
我能够通过“sense”创建具有相同映射的索引,但从 java 应用程序中收到错误。
我正在使用“org.springframework.data.elasticsearch.core.ElasticsearchTemplate”从我的 Java 应用程序创建弹性搜索索引。
我使用相同的 ElasticsearchTemplate 来保存和查询数据。
为具有不同映射文件的所有不同类型创建索引时,它是成功的,但是在保存数据时,我收到错误
java.lang.IllegalArgumentException: [location] is defined as an object in mapping [esIndex] but this name is already used for a field in other types
我对所有类型的“位置”都有相同的映射
"location": {
"geohash": true,
"lat_lon": true,
"store": true,
"type": "geo_point"
}
仅供参考-这是我的 es_index 映射
{
"es_index": {
"aliases": {
"es_index1": {}
},
"mappings": {
"type1": {
"properties": {
"field1": {
"type": "string",
"analyzer": "nGram_analyzer",
"search_analyzer": "whitespace_analyzer"
},
"field2": {
"type": "string",
"index": "no"
},
"field3": {
"type": "string",
"analyzer": "nGram_analyzer",
"search_analyzer": "whitespace_analyzer"
},
"field4": {
"type": "string",
"index": "no"
},
"location": {
"type": "geo_point",
"store": true,
"lat_lon": true,
"geohash": true
}
}
},
"type2": {
"properties": {
"field1": {
"type": "string",
"analyzer": "nGram_analyzer",
"search_analyzer": "whitespace_analyzer"
},
"field5": {
"type": "string",
"analyzer": "nGram_analyzer",
"search_analyzer": "whitespace_analyzer",
"include_in_all": true
},
"field4": {
"type": "string",
"index": "no"
},
"location": {
"type": "geo_point",
"store": true,
"lat_lon": true,
"geohash": true
},
"field6": {
"type": "string",
"index": "no"
}
}
}
},
"settings": {
"index": {
"creation_date": "1491466792565",
"include_in_all": "false",
"uuid": "uuid....",
"number_of_replicas": "1",
"analysis": {
"filter": {
"nGram_filter": {
"max_gram": "75",
"type": "edgeNGram",
"min_gram": "2",
"token_chars": [
"letter",
"digit",
"punctuation",
"symbol"
]
}
},
"analyzer": {
"nGram_analyzer": {
"type": "custom",
"filter": [
"lowercase",
"asciifolding",
"nGram_filter"
],
"tokenizer": "keyword"
},
"whitespace_analyzer": {
"type": "custom",
"filter": [
"lowercase",
"asciifolding"
],
"tokenizer": "keyword"
}
}
},
"number_of_shards": "8",
"version": {
"created": "2040499"
}
}
},
"warmers": {}
}
}
这是什么原因,我该如何解决?
【问题讨论】:
-
你能发布你的索引映射吗?
curl localhost:9200/es_index?pretty -
@fylie:我编辑了问题
标签: java spring elasticsearch