I have elastic search index with different types in it. And every type contains some default fields and some extra fields based on type. Every type will have location object which stores lat and lon. Sample data that I have in my elastic search index is
[{
"_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
}
}
}]
I was able to create the index with same mappings through "sense" but getting an error from java application.
I am using "org.springframework.data.elasticsearch.core.ElasticsearchTemplate" for creating the elastic search index from my Java application.
I am using the same ElasticsearchTemplate to save and query the data.
When creating index for all the different types with different mapping files, it is successful but while saving the data, I am getting error as
java.lang.IllegalArgumentException: [location] is defined as an object in mapping [esIndex] but this name is already used for a field in other types
And I have same mapping for "location" in all the types
"location": {
"geohash": true,
"lat_lon": true,
"store": true,
"type": "geo_point"
}
FYI- Here is my es_index mapping
{
"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": {}
}
}
What is the reason for it and how can I resolve it?
curl localhost:9200/es_index?pretty
– fylie