2

I'm trying to index a document in elasticsearch using the following mapping:

{"thread": {"properties":{"message":{"type": "nested", "properties": {"message_id": {"type":"string"}, "message_text":{"type":"string"}, "message_nick":{"type":"string"}}}}}}

Then using this to add the mapping in Java:

CreateIndexRequestBuilder indexRequest = client.admin().indices().prepareCreate(INDEX).addMapping("message", mapping);

But I am getting the following error:

Caused by: org.elasticsearch.index.mapper.MapperParsingException: Root type mapping not empty after parsing! Remaining fields:   [mappings : {thread={properties={message={properties={message_text={type=string}, message_nick={type=string}, message_id={type=string}}, type=nested}}}}]

Can anyone let me know how I'm getting this error?

2
  • do you want to store a whole thread as a single document in elasticsearch? It seems that you have a mapping for a "thread" type, but you are trying to create a mapping for the "message" type. Commented Mar 27, 2015 at 15:45
  • I'm trying to add mapping to the "message" type. Ultimately I wanted messages to be nested to I can search for occurrences of a keyword within the thread field but also find if any messages hold that keyword also. Can nested documents help me do this? Commented Mar 29, 2015 at 16:26

1 Answer 1

2

I don't know the details for your exact mapping, but I had a similar problem and just realized that when you add mappings via the java API, you need to remove the json object right below the root.

For example, the mapping I tried to add was:

{"mappings":{"_default_":{"date_detection":false,"dynamic_templates":[{"dates":{"match":".*Date|date","match_pattern":"regex","mapping":{"type":"date"}}}]}}}

The above added fine using the REST API, but failed using the Java API with the same error you mentioned.

I removed the "mappings" json object and it fixed the issue. Final mapping that worked was:

{"_default_":{"date_detection":false,"dynamic_templates":[{"dates":{"match":".*Date|date","match_pattern":"regex","mapping":{"type":"date"}}}]}}
Sign up to request clarification or add additional context in comments.

1 Comment

One and a half Year old but you still made my day. Same belongs to the Javascript API - Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.