Hi,
We are working on a system that requires each tenant to have their own
index. Each index may have multiple object types (in the example
below: aaa and xxx). We need to control the field names so we wanted
to use the conf/dynamic-mapping.json file to define the field names in
advance.
We prefer to do this when the system is loaded instead of having to
redefine it for each tenant when it is created.
The dynamic-mapping.json includes two objects, like so:
{
"xxx" : {
"type" : "object",
"path" : "just_name",
"properties" : {
"yyy" : {
"type" : "object",
"path" : "just_name",
"properties" : {
"field3" : { "index_name" : "f3", type: "string" },
"field1" : { "index_name" : "f1", type: "string" }
}
}
}
},
"aaa" : {
"type" : "object",
"path" : "just_name",
"properties" : {
"bbb" : {
"type" : "object",
"path" : "just_name",
"properties" : {
"field2" : { "index_name" : "f2", type: "string" },
"field1" : { "index_name" : "f1", type: "string" }
}
}
}
}
}
When doing this, we get an exeption when indexing this document:
curl -XPUT http://localhost:9200/index/xxx/1 -d '{"yyy": {field1:
"test1", field3: "test3"}}'
Exception is:
org.elasticsearch.index.mapper.MapperParsingException: Mapping must
have the type
as the root object
at
org.elasticsearch.index.mapper.xcontent.XContentDocumentMapperParser.extractMapping(XContentDocumentMapperParser.java:
235)
at
org.elasticsearch.index.mapper.xcontent.XContentDocumentMapperParser.parse(XContentDocumentMapperParser.java:
106)
at
org.elasticsearch.index.mapper.xcontent.XContentDocumentMapperParser.parse(XContentDocumentMapperParser.java:
46)
When working with a single object in the dynamic-mapping.json it works
OK.
Another thing we tried is using the config/mappings/_default folder to
achieve this (created two files called aaa.json and xxx.json with the
relevant content in each file). This resulted in a response from
elastic search:
{"error":"nested: "}
without an exception on ES.
BTW, in the documentation, it says that the file name is dynamic-
mapping.json (http://www.elasticsearch.com/docs/elasticsearch/mapping/
dynamic_mapping/). We also saw a reference to this file in the code.
In one of the bug fixes (http://github.com/elasticsearch/elasticsearch/
issues/closed#issue/275) it says that the file is now called default-
mapping.json or is this a different file? Which should be used for
what?
Thanks,
Tal