How to get documents added as-is due to fields with dot in them?

So basically I've got this json file being generated by a system that didn't know how to write json files.

Here's the example of my problem:

{"snapshot.updated_by.uid": "mcarter", 
 "snapshot.updated_by": "michael carter"}

So how do I get Elasticsearch to escape that .?

Hello and welcome,

What is exactly your issue? And what you want the output to be?

The document you shared has 2 fields with literal dots in the name.

I'd like it to use the . in the field name rather than separating the mapping into two/three separate fields.

Because of the overlap I get an error trying to add the document.

Failure to add document: co.elastic.clients.elasticsearch._types.ElasticsearchException@3fefbb9c[
  response=ErrorResponse: {"error":{"type":"document_parsing_exception","reason":"[1:1453] failed to parse field [snapshot.updated_by] of type [text] in document with id

and this one

Error saving mapping

Error saving mapping: can't merge a non object mapping [snapshot.updated_by] with an object mapping

Also if the field starts with a . like {".myfield": "data"} I get an error that the field name can't contain whitespace.

So how do I get Elasticsearch to stop using the . as a delimiter?

I don't think you can.
I'd change the field names on the client side and replace all dots by another character like - or _.

Could you share a bit more of your code? How do you index a document?

Hi, I think you can use nested field format like [snapshot][updated_by] format so the elastic field will become snapshot.updated_by.

I don't know this is the escape you find or not.

The dot character is reserved as it indicates flattened fields.

You have two options:

  1. You can use a different character for a delimiter for example _:
{"snapshot_updated_by_uid": "mcarter", 
 "snapshot_updated_by": "michael carter"}
  1. You can refactor this to reflect nested fields, which is what the dots represent:
{"snapshot.updated_by.uid": "mcarter", 
 "snapshot.updated_by.name": "michael carter"}

This example would be the same as sending in:

{
  "snapshot": {
    "updated_by": {
      "uid": "mcarter",
      "name": "michael carter"
    }
}
1 Like

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.