# Mapping question for parentname

**URL:** <https://discuss.elastic.co/t/mapping-question-for-parentname/74100>\
**Category:** Elasticsearch\
**Created:** [February 6, 2017, 5:23pm UTC](https://discuss.elastic.co/t/mapping-question-for-parentname/74100 "2017-02-06T17:23:53Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![billnbell](https://avatars.discourse-cdn.com/v4/letter/b/eb8c5e/32.png) [@billnbell](https://discuss.elastic.co/u/billnbell)\
**Post date:** [February 6, 2017, 5:23pm UTC](https://discuss.elastic.co/t/mapping-question-for-parentname/74100/1 "2017-02-06T17:23:53Z")

</div>

> <https://github.com/elastic/elasticsearch/issues/22980>

Anyway to do this? I am new to ELK...

I would like to define: copy\_to: {parentname}\_all. Today I can only use {name} which does not allow the object of the parent to be referenced. I want to take fields and aggregate all children into a terms search. Kinda like \_all but at the object level.

Here is an example: Note this is kinda useless, since I want to use {parentname}.

```
PUT /index2
{
  "mappings": {
    "_default_": {
      "dynamic_templates": [
        {
          "nested_template": {
            "path_match": "*.*",
            "match_mapping_type": "string",
            "mapping": {
              "copy_to": "{name}_all",
              "type": "string",
              "index": "not_analyzed"
            }
          }
        },
        {
          "nested2_template": {
            "match": "*_all",
            "match_mapping_type": "string",
            "mapping": {
              "type": "string",
              "index": "not_analyzed"
            }
          }
        },
        {
          "nested2_template": {
            "path_unmatch": "*.*",
            "match_mapping_type": "string",
            "mapping": {
              "type": "string",
              "index": "not_analyzed"
            }
          }
        },
        {
          "notanalyzed": {
            "match": "*",
            "match_mapping_type": "string",
            "mapping": {
              "type": "string",
              "index": "not_analyzed"
            }
          }
        }
      ]
    }
  }
}
```

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [February 7, 2017, 8:11am UTC](https://discuss.elastic.co/t/mapping-question-for-parentname/74100/2 "2017-02-07T08:11:32Z")

</div>

The issue got a `discuss` label, so it will be checked out soon (those kind of issues are talked about regurlarly). Please dont cross post into the forum, just because you did not get an immediate answer.

have you considered using an ingest processor?

---

<div class="post-metadata">

**Author:** ![billnbell](https://avatars.discourse-cdn.com/v4/letter/b/eb8c5e/32.png) [@billnbell](https://discuss.elastic.co/u/billnbell)\
**Post date:** [February 8, 2017, 4:08am UTC](https://discuss.elastic.co/t/mapping-question-for-parentname/74100/3 "2017-02-08T04:08:59Z")

</div>

OK. Is there another way to solve this?

address (object)  
address.street  
address.city  
address.state  
address.zip

search: address: 80031

I don't want it to show in \_source if possible, but want that type of query to work. A copy\_to field would be good, since it does not show in \_source. But when processing no idea how I can create a copy\_to field "text" and copy all the children nodes into it.

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [February 8, 2017, 8:20am UTC](https://discuss.elastic.co/t/mapping-question-for-parentname/74100/4 "2017-02-08T08:20:07Z")

</div>

Hey,

then `copy_to` sounds right, how about something like this?

```auto
PUT /index2
{
  "mappings": {
    "_default_": {
      "dynamic_templates": [
        {
          "nested_template": {
            "path_match": "address.*",
            "match_mapping_type": "string",
            "mapping": {
              "copy_to": "address.full",
              "type": "string"
            }
          }
        }
      ]
    }
  }
}

PUT index2/foo/bar
{
  "address" : {
    "street" : "Baker Street 223",
    "city": "London"
  }
}

GET index2/_search?q=address.full=baker

GET index2/_search?q=address.full=london

```

--Alex

---

<div class="post-metadata">

**Author:** ![billnbell](https://avatars.discourse-cdn.com/v4/letter/b/eb8c5e/32.png) [@billnbell](https://discuss.elastic.co/u/billnbell)\
**Post date:** [February 9, 2017, 7:26am UTC](https://discuss.elastic.co/t/mapping-question-for-parentname/74100/5 "2017-02-09T07:26:51Z")

</div>

Yeah. Pefect. However, we want it to be generic, we don't know the  
"address' - and want it to work on any child - as we add more objects to  
the index.

PUT index2/address/1 { "address" : { "street" : "Baker Street 223", "city":  
"London" } }  
PUT index2/pizza/2 { "pizza" : { "type" : "Large", "price": "13.00" } }  
PUT index2/physicians/3 { "name" : { "first" : "Phil", "last": "Simms" } }

---

<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:** [March 9, 2017, 7:27am UTC](https://discuss.elastic.co/t/mapping-question-for-parentname/74100/6 "2017-03-09T07:27:00Z")

</div>

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