# Ability to configure "root" field for an object type

**URL:** <https://discuss.elastic.co/t/ability-to-configure-root-field-for-an-object-type/170662>\
**Category:** Elasticsearch\
**Created:** [March 3, 2019, 10:36pm UTC](https://discuss.elastic.co/t/ability-to-configure-root-field-for-an-object-type/170662 "2019-03-03T22:36:52Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![sdavids](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sdavids/32/32847_2.png) [@sdavids](https://discuss.elastic.co/u/sdavids)\
**Post date:** [March 3, 2019, 10:36pm UTC](https://discuss.elastic.co/t/ability-to-configure-root-field-for-an-object-type/170662/1 "2019-03-03T22:36:52Z")

</div>

I have a mapping definition with multiple object types that looks like:

```
{
    "mappings": {
        "_doc": {
            "properties": {
                "identifier": {
                    "type": "object",
                    "properties": {
                        "id": {
                            "type": "keyword"
                        },
                        "upstream": {
                            "type": "keyword"
                        }
                    }
                },
                "document": {
                    "type": "object",
                    "properties": {
                        "engine": {
                            "type": "keyword"
                        },
                        "content": {
                            "type": "text"
                        }
                    }
                }
            }
        }
    }
}

```

This will build fields: identifier.id, identifier.upstream, document.engine, and document.query. I would like to allow additional mappings for the "root" fields e.g. the plain "identifier" and "document" field.

For the "identifier" field I would like to be able to search across all subfields (without requiring users to specify "identifier.\*") which I believe should be a simple keyword type with all subfields specifying: "copy\_to": "identifier". Likewise, for the "document" field I would like to set it up as an alias field which will point to populated "document.content" field. I tried updating the "type" to the desired field types but was unable to create the index, can someone please let me know if this is achievable.

_ **Update:** _  
I also tried to flatten out the structure myself and do:

```
"properties": {
    "identifier": {
        "type": "keyword"
    },
    "identifier.id": {
        "type": "keyword",
        "copy_to": "identifier"
    },
    "identifier.upstream": {
        "type": "keyword",
        "copy_to": "identifier"
    },
    "document": {
        "type": "alias",
        "path": "document.content"
    },
    "document.engine": {
        "type": "keyword"
    },
    "document.content": {
        "type": "text"
    }
}

```

But received the following error:

> Failed to parse mapping [\_doc]: Can't merge a non object mapping [document] with an object mapping [document]

---

<div class="post-metadata">

**Author:** ![glenacota](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/glenacota/32/41367_2.png) [@glenacota](https://discuss.elastic.co/u/glenacota)\
**Post date:** [March 4, 2019, 4:39pm UTC](https://discuss.elastic.co/t/ability-to-configure-root-field-for-an-object-type/170662/2 "2019-03-04T16:39:09Z")

</div>

Hi,  
you are already defining a mapping for `identifier` and `document`, and that is an object datatype. You should consider using `copy_to`, but using a different field name than the ones already defined in the mapping. What about

```auto
...
"identifier": {
  "type": "object",
  "properties": {
    "id": {
      "type": "keyword"
      "copy_to": "identifier.*"
    },
    "upstream": {
      "type": "keyword"
      "copy_to": "identifier.*"
    }
  }
},
...

```

That you can query this way

```auto

GET your_index/_search
{
  "query": {
    "match": {
      "identifier.*": "the_id"
    }
  }
}

```

?

---

<div class="post-metadata">

**Author:** ![sdavids](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sdavids/32/32847_2.png) [@sdavids](https://discuss.elastic.co/u/sdavids)\
**Post date:** [March 4, 2019, 5:08pm UTC](https://discuss.elastic.co/t/ability-to-configure-root-field-for-an-object-type/170662/3 "2019-03-04T17:08:29Z")

</div>

So, the primary reason why I am doing this is allow users to perform logical fielded searches rather than having to know all of the various subfields (though it would be available to them if they _really_ needed it). I am afraid that if I ask users to user to run their identifier searches via "identifier.\*" it is leaking too many details of the underlying indexing scheme which I would like to avoid.

I wanted to get clarification on if this is possible in Elasticsearch or not (it seems like it is not) -- though this seems to be a limitation on Elasticsearch itself and not Lucene as the underlying Lucene index structure can accommodate a "root" field index type.

Since this request is primarily focused around abstracting the underlying index structure from the user (via query\_string queries), another option would be to dynamically map fields at query time. Is there a way to indicate to the Elasticsearch query parser to map query fields of "document" to "document.content" or "identifier" to "identifier.\*"?

---

<div class="post-metadata">

**Author:** ![glenacota](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/glenacota/32/41367_2.png) [@glenacota](https://discuss.elastic.co/u/glenacota)\
**Post date:** [March 4, 2019, 5:34pm UTC](https://discuss.elastic.co/t/ability-to-configure-root-field-for-an-object-type/170662/4 "2019-03-04T17:34:25Z")

</div>

I'm not sure about what information is leaking, as you'll expose the underlying structure anyway by allowing queries on `identifier.id` and `identifier.upstream`.

---

<div class="post-metadata">

**Author:** ![sdavids](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sdavids/32/32847_2.png) [@sdavids](https://discuss.elastic.co/u/sdavids)\
**Post date:** [March 4, 2019, 5:42pm UTC](https://discuss.elastic.co/t/ability-to-configure-root-field-for-an-object-type/170662/5 "2019-03-04T17:42:49Z")

</div>

Sure, if we documented the fact that those fields are available then you are correct we would be leaking the information. Now, if we say the only "supported" field that they could search on is simply "identifier" then that provides us flexibility in the future while also not exposing that those underlying fields are actually there.

---

<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:** [April 1, 2019, 5:42pm UTC](https://discuss.elastic.co/t/ability-to-configure-root-field-for-an-object-type/170662/6 "2019-04-01T17:42:50Z")

</div>

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