Java 弹性搜索非法参数异常
我有不同类型的弹性搜索索引。 每个类型都包含一些默认字段和一些基于类型的额外字段。 每种类型都有存储lat和lon的location对象。 我的弹性搜索索引中的示例数据是Java 弹性搜索非法参数异常,java,spring,elasticsearch,Java,Spring,elasticsearch,我有不同类型的弹性搜索索引。 每个类型都包含一些默认字段和一些基于类型的额外字段。 每种类型都有存储lat和lon的location对象。 我的弹性搜索索引中的示例数据是 [{ "_index": "es_index", "_type": "type1", "_id": "id1", "_source": { "name": "name", "type1field": "value", "location": {
[{
"_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_索引映射
{
"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": {}
}
}
出现此问题的原因是什么?如何解决此问题?错误消息表明,您试图在同一索引中以两种不同的方式(在不同的文档类型中)映射同一字段名
- 这可能是因为您实际编写了此重复映射
- 如果启用了动态映射,并且在更新使用相同名称的其他类型的映射之前插入了包含该字段名称的文档,也可能发生这种情况
"mappings": {
"books": {
"properties":{
"title":{
"type":"text"
},
...
以后不能在同一索引中使用
"films": {
"properties":{
"title":{
"type":"keyword"
}
}
标题字段在索引中只有一个映射定义
标题字段为索引中的所有类型共享
类型与数据库表不同。
- 它们共享Lucene索引中的字段
- 它们有点像大共享索引中的视图
<>如果这只是一个动态映射进入并破坏索引的例子,那么,请考虑关闭它。想象一下,在生产环境中发生这种情况是多么令人高兴。错误消息表明,您正试图在同一索引中以两种不同的方式(在不同的文档类型中)映射同一字段名
- 这可能是因为您实际编写了此重复映射
- 如果启用了动态映射,并且在更新使用相同名称的其他类型的映射之前插入了包含该字段名称的文档,也可能发生这种情况
"mappings": {
"books": {
"properties":{
"title":{
"type":"text"
},
...
以后不能在同一索引中使用
"films": {
"properties":{
"title":{
"type":"keyword"
}
}
标题字段在索引中只有一个映射定义
标题字段为索引中的所有类型共享
类型与数据库表不同。
- 它们共享Lucene索引中的字段
- 它们有点像大共享索引中的视图
<>如果这只是一个动态映射进入并破坏索引的例子,那么,请考虑关闭它。想象一下,在生产中实现这一点是多么令人高兴。你能发布你的索引映射吗
curl localhost:9200/es_index?pretty
@fylie:我编辑了这个问题你能发布你的索引映射吗curl localhost:9200/es_index?pretty
@fylie:我编辑了这个问题我想这个问题以前已经回答过很多次了。对于刚接触Elasticsearch的人来说,这是第一次猛然醒悟,他们希望它能像一个典型的数据库一样运行。在我的例子中,第二和第三种选择被排除在外。我对所有类型都有相同的映射。“位置”:{“geohash”:true,“lat_lon”:true,“store”:true,“type”:“geo_point”}但是我仍然得到这个错误,这可能发生的任何其他原因?我也更新了这个问题。当我尝试使用“sense”时,我能够使用相同的映射创建索引。但在java应用程序中,情况并非如此@joshp@Raghavendra如果GET/yourindex/_mapping检索到的实际映射对于每个类型的字段都具有相同的属性,并且您尝试添加的映射也相同,那么我不知道它为什么会抱怨。通常在实践中,动态映射是一个问题,有人在应用映射之前插入了文档。但若那个并没有发生,我不知道。我只是修改了这个问题并添加了我的es索引映射。我想这个问题以前已经被回答过很多次了。对于刚接触Elasticsearch的人来说,这是第一次猛然醒悟,他们希望它能像一个典型的数据库一样运行。在我的例子中,第二和第三种选择被排除在外。我对所有类型都有相同的映射。“位置”:{“geohash”:true,“lat_lon”:true,“store”:true,“type”:“geo_point”}但是我仍然得到这个错误,这可能发生的任何其他原因?我也更新了这个问题。当我尝试使用“sense”时,我能够使用相同的映射创建索引。但情况并非如此