# Is there a way to allow dots in the fieldname?

**URL:** https://discuss.elastic.co/t/is-there-a-way-to-allow-dots-in-the-fieldname/90134
**Category:** Elasticsearch
**Created:** [June 20, 2017, 5:35pm UTC](https://discuss.elastic.co/t/is-there-a-way-to-allow-dots-in-the-fieldname/90134 "2017-06-20T17:35:09Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![animageofmine](https://avatars.discourse-cdn.com/v4/letter/a/7feea3/32.png) [@animageofmine](https://discuss.elastic.co/u/animageofmine)
#### Post date: [June 20, 2017, 5:35pm UTC](https://discuss.elastic.co/t/is-there-a-way-to-allow-dots-in-the-fieldname/90134/1 "2017-06-20T17:35:10Z")

</div>

The title says it all.

We are using ES 5.3.

---

<div class="post-metadata">

### Author: ![polyfractal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/polyfractal/32/48162_2.png) [@polyfractal](https://discuss.elastic.co/u/polyfractal)
#### Post date: [June 20, 2017, 8:24pm UTC](https://discuss.elastic.co/t/is-there-a-way-to-allow-dots-in-the-fieldname/90134/2 "2017-06-20T20:24:14Z")

</div>

Dots are allowed:

```auto
POST /test/test/
{
  "foo.bar.baz": "bizz buzz"
}

{
    "_index": "test",
    "_type": "test",
    "_id": "AVzHK7SvBQImgzk991KA",
    "_version": 1,
    "result": "created",
    "_shards": {
        "total": 2,
        "successful": 1,
        "failed": 0
    },
    "created": true
}

```

```auto
GET /test/test/AVzHK7SvBQImgzk991KA

{
    "_index": "test",
    "_type": "st",
    "_id": "AVzHK7SvBQImgzk991KA",
    "_version": 1,
    "found": true,
    "_source": {
        "foo.bar.baz": "bizz buzz"
    }
}

```

---

<div class="post-metadata">

### Author: ![animageofmine](https://avatars.discourse-cdn.com/v4/letter/a/7feea3/32.png) [@animageofmine](https://discuss.elastic.co/u/animageofmine)
#### Post date: [June 20, 2017, 9:34pm UTC](https://discuss.elastic.co/t/is-there-a-way-to-allow-dots-in-the-fieldname/90134/3 "2017-06-20T21:34:38Z")

</div>

Here is what I get. Please note that I don't want the data to be nested. By default, if you use dots, ES uses nested type.

```
PUT /fieldnamestest/mytype/1
{
    "a...b" : "test"
}

```

RESPONSE:

```
{
   "error": {
      "root_cause": [
         {
            "type": "mapper_parsing_exception",
            "reason": "failed to parse"
         }
      ],
      "type": "mapper_parsing_exception",
      "reason": "failed to parse",
      "caused_by": {
         "type": "illegal_argument_exception",
         "reason": "object field starting or ending with a [.] makes object resolution ambiguous: [a...b]"
      }
   },
   "status": 400
}
```

---

<div class="post-metadata">

### Author: ![polyfractal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/polyfractal/32/48162_2.png) [@polyfractal](https://discuss.elastic.co/u/polyfractal)
#### Post date: [June 20, 2017, 9:42pm UTC](https://discuss.elastic.co/t/is-there-a-way-to-allow-dots-in-the-fieldname/90134/4 "2017-06-20T21:42:23Z")

</div>

Ah, yeah, that's not allowed 🙂

To clarify, dots only signify "objects", unless you've explicitly mapped it to `nested`. E.g. this:

```auto
{
  "foo.bar.baz": 123
}

```

is equivalent to:

```auto
{
  "foo": {
    "bar": {
      "baz": 123
    }
  }
}

```

But it's just an [Object Type](https://www.elastic.co/guide/en/elasticsearch/reference/current/object.html), not a [Nested Type](https://www.elastic.co/guide/en/elasticsearch/reference/current/nested.html) unless you explictly map it so. See: [https://www.elastic.co/guide/en/elasticsearch/guide/current/nested-objects.html](https://www.elastic.co/guide/en/elasticsearch/guide/current/nested-objects.html) for more details

But getting back to your question, you're right that dots signify object heirarchy, so you can't use them in the manner shown above, as just regular characters. Sorry, I misunderstood your original question.

---

<div class="post-metadata">

### Author: ![animageofmine](https://avatars.discourse-cdn.com/v4/letter/a/7feea3/32.png) [@animageofmine](https://discuss.elastic.co/u/animageofmine)
#### Post date: [June 20, 2017, 9:52pm UTC](https://discuss.elastic.co/t/is-there-a-way-to-allow-dots-in-the-fieldname/90134/5 "2017-06-20T21:52:02Z")

</div>

@polyfractal

No worries. I tried escaping the dots and it seems to work. Is that a good solution?

```
PUT /fieldnamestest/mytype/1
{
    "a\\.\\.\\.b" : "test"
}

```

Also, is this a valid configuration in version 5.x? See [this](https://www.elastic.co/guide/en/elasticsearch/reference/2.4/dots-in-names.html) document for details. I tried it and it does not work for 5.x, but works for 2.4.x

export ES\_JAVA\_OPTS="-Dmapper.allow\_dots\_in\_name=true"

---

<div class="post-metadata">

### Author: ![polyfractal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/polyfractal/32/48162_2.png) [@polyfractal](https://discuss.elastic.co/u/polyfractal)
#### Post date: [June 21, 2017, 1:36pm UTC](https://discuss.elastic.co/t/is-there-a-way-to-allow-dots-in-the-fieldname/90134/6 "2017-06-21T13:36:55Z")

</div>

That "works", but it's probably not quite what you want. If you check the mappings you'll see:

```auto
GET /fieldnamestest/_mapping

{
    "fieldnamestest": {
        "mappings": {
            "mytype": {
                "properties": {
                    "a\\": {
                        "properties": {
                            "\\": {
                                "properties": {
                                    "\\": {
                                        "properties": {
                                            "b": {
                                                "type": "text",
                                                "fields": {
                                                    "keyword": {
                                                        "type": "keyword",
                                                        "ignore_above": 256
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}

```

E.g. it's not really escaping the dots, it's escaping the slashes and then using the slashes as object names. Fundamentally it doesn't really matter, since the object name is "flattened" in Lucene to `"a\\.\\.\\.b"` anyway, but it's good to be aware of because `"a\\.\\.\\.c"` will _technically_ be considered a sub-object of `"a\\.\\.\\"`.

If possible I'd probably avoid doing that, since having slashes as an object name is bound to be confusing, and potentially made illegal in future versions of Elasticsearch (we'd like to lock down field name validation in the future, to prevent things like unprintable characters, etc)

> [@animageofmine](#):
>
> Also, is this a valid configuration in version 5.x? See this document for details. I tried it and it does not work for 5.x, but works for 2.4.x

That's an old setting, and I don't think it's available in 5.x anymore. It was used because, in versions 2.0 - 2.4, dots were completely forbidden. E.g. `foo.bar.baz` was not allowed, you had to write `foo_bar_baz`. The restriction was loosened in 2.4, and `allow_dots_in_name` was added to expose that loosened restriction.

I believe it went away in 5.x because the default is to allow dots. But note, the dots are what we discussed above... objects in objects, etc.

You can read more about that change here: [Mappings: Allow to force dots in field names by rjernst · Pull Request #19937 · elastic/elasticsearch · GitHub](https://github.com/elastic/elasticsearch/pull/19937)

---

<div class="post-metadata">

### Author: ![animageofmine](https://avatars.discourse-cdn.com/v4/letter/a/7feea3/32.png) [@animageofmine](https://discuss.elastic.co/u/animageofmine)
#### Post date: [June 21, 2017, 3:15pm UTC](https://discuss.elastic.co/t/is-there-a-way-to-allow-dots-in-the-fieldname/90134/7 "2017-06-21T15:15:11Z")

</div>

Thanks so much for the detailed explanation. The escape characters won't work because of the hierarchical mapping.

I guess the best way is to simply avoid the dots in the fieldnames. Are there any other illegal characters in fieldnames that I should be aware of?

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [July 19, 2017, 3:15pm UTC](https://discuss.elastic.co/t/is-there-a-way-to-allow-dots-in-the-fieldname/90134/8 "2017-07-19T15:15:11Z")

</div>

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