Hi,
I'm having the following problem:
-
Initial state
I put two different mappings with a field named the same way into a
single index.
After that I indexed two documents one for each mapping.Consider this as an example
Mappings
curl -XPUT 'http://localhost:9200/localtest/map1/_mapping' -d '{
"map1": {
"_source" : {
"enabled" : false
},
"date_formats": ["date_time", "yyyyMMddHHmmss",
"yyyyMMddHHmmssSSS"],
"_all": {
"enabled": true,
"store": "yes"
},
"properties": {
"field1": {
"type": "date",
"store": "yes",
"format": "yyyyMMddHHmmssSSS",
"include_in_all": false
}
}
}
}'
curl -XPUT 'http://localhost:9200/localtest/map2/_mapping' -d '{
"map2": {
"_source" : {
"enabled" : false
},
"date_formats": ["date_time", "yyyyMMddHHmmss",
"yyyyMMddHHmmssSSS"],
"_all": {
"enabled": true,
"store": "yes"
},
"properties": {
"field1": {
"type": "string",
"store": "yes",
"term_vector": "yes",
"include_in_all": false
}
}
}
}'
documents
curl -XPUT 'http://localhost:9200/localtest/map1/1' -d '{
"field1" : "20110214172449000"
}'
curl -XPUT 'http://localhost:9200/localtest/map2/2' -d '{
"field1" : "Test map2 with string type field"
}'
If I execute a search over this index using the field1 seen as string,
the query breaks. But if I execute a search over this index using the
field1 seen as date, the query succeeds.
Query example:
curl -XGET 'http://localhost:9200/localtest//_search?pretty=true' -d
'{
"fields": "",
"from" : 0, "size" : 100,
"query":{
"bool":{
"must":{"field":{"field1":""Test""}}
}
}
}'
Returned error:
MapperParsingException[failed to parse date field, tried both date
format [yyyyMMddHHmmssSSS], and timestamp number]; nested:
IllegalArgumentException[Invalid format: "Test"];
It seems that the first mapping is the one that determines the field
type, disregarding any following mappings.
Is it correct? If so, what's the correct way to use mappings?
Best regards
Simone