# How to specify mapping to disable index for all fields of an object type

**URL:** <https://discuss.elastic.co/t/how-to-specify-mapping-to-disable-index-for-all-fields-of-an-object-type/33956>\
**Category:** Elasticsearch\
**Created:** [November 6, 2015, 8:44am UTC](https://discuss.elastic.co/t/how-to-specify-mapping-to-disable-index-for-all-fields-of-an-object-type/33956 "2015-11-06T08:44:12Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![philips](https://avatars.discourse-cdn.com/v4/letter/p/8797f3/32.png) [@philips](https://discuss.elastic.co/u/philips)\
**Post date:** [November 6, 2015, 8:44am UTC](https://discuss.elastic.co/t/how-to-specify-mapping-to-disable-index-for-all-fields-of-an-object-type/33956/1 "2015-11-06T08:44:12Z")

</div>

I have an field with type object in my document. This field has a lot of fields inside (and possibly additional other fields may be added later since we crawl data from external sources). For example:

```
{
  "field1": 1,
  "field2": 2,
  "obj1": {
     "field1": "value1",
     "field2": "value2",
     ...
     "fieldn": "valuen",
     "new_field": "value",
     "additional_1": 123
  }
}

```

Instead of specifying the mapping for all fields one by one, are there any convinient way to tell the mapping that all fields under "obj1" is not indexed?

We don't want newly added fields under obj1 to be indexed too. We may disable dynamic mapping, but it may disrupt the crawlers. It would be nice if the newly added fields are added, but not indexed.

Thank you

---

<div class="post-metadata">

**Author:** ![GlenRSmith](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/glenrsmith/32/44925_2.png) [@GlenRSmith](https://discuss.elastic.co/u/GlenRSmith)\
**Post date:** [November 8, 2015, 6:22am UTC](https://discuss.elastic.co/t/how-to-specify-mapping-to-disable-index-for-all-fields-of-an-object-type/33956/2 "2015-11-08T06:22:31Z")

</div>

I'm assuming what you want is these to be unanalyzed, and not just omitted from indexing altogether, otherwise, "dynamic": false on obj1 would suffice. Not sure whether your "obj1" is currently mapped as "nested", so I'm demonstrating that this solution works regardless (while at the same time demonstrating the ability of wildcard matching).

Your solution is based on **dynamic\_templates** with a **path\_match** rule.

Let me know if this isn't sufficiently clear.

```auto
# delete the index
DELETE dynamic_object_nope

# create the index with a mapping that includes dynamic templates
POST dynamic_object_nope
{
  "settings": {
    "index": {
      "number_of_replicas": "0",
      "number_of_shards": "1"
    }
  },
  "mappings": {
    "test_type": {
      "dynamic_templates": [
        {
          "object1_field": {
            "path_match": "obj*.*",
            "mapping": {
              "index": "not_analyzed"
            }
          }
        }
      ],
      "properties": {
        "field1": {
          "type": "integer"
        },
        "obj1": {
          "type": "object"
        },
        "obj2": {
          "type": "nested"
        }
      }
    }
  }
}

POST dynamic_object_nope/test_type
{
  "field1": 1,
  "field2": 2,
  "obj1": {
    "new_field": "value",
    "additional_1": 123
  },
  "obj2": {
    "new_field": "value",
    "additional_1": 123
  }
}

POST _refresh

# examine mapping
GET dynamic_object_nope/test_type/_mapping

```

**path\_match** is specifically available for this situation (as opposed to "match", which would just match top-level fields).

Notice that it worked on both the object declared as `nested` (obj2) and not (obj1). In both cases, "new\_field" got the "index": "not\_analyzed" treatment. That doesn't show up on "additional\_1" because numerics are automatically not\_analyzed already.

```auto
{
   "dynamic_object_nope": {
      "mappings": {
         "test_type": {
            "dynamic_templates": [
               {
                  "object1_field": {
                     "mapping": {
                        "index": "not_analyzed"
                     },
                     "path_match": "obj*.*"
                  }
               }
            ],
            "properties": {
               "field1": {
                  "type": "integer"
               },
               "field2": {
                  "type": "long"
               },
               "obj1": {
                  "properties": {
                     "additional_1": {
                        "type": "long"
                     },
                     "new_field": {
                        "type": "string",
                        "index": "not_analyzed"
                     }
                  }
               },
               "obj2": {
                  "type": "nested",
                  "properties": {
                     "additional_1": {
                        "type": "long"
                     },
                     "new_field": {
                        "type": "string",
                        "index": "not_analyzed"
                     }
                  }
               }
            }
         }
      }
   }
}

```

---

<div class="post-metadata">

**Author:** ![philips](https://avatars.discourse-cdn.com/v4/letter/p/8797f3/32.png) [@philips](https://discuss.elastic.co/u/philips)\
**Post date:** [November 9, 2015, 7:12am UTC](https://discuss.elastic.co/t/how-to-specify-mapping-to-disable-index-for-all-fields-of-an-object-type/33956/3 "2015-11-09T07:12:37Z")

</div>

Thanks @GlenRSmith for the explanation

---

<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 5, 2017, 11:39pm UTC](https://discuss.elastic.co/t/how-to-specify-mapping-to-disable-index-for-all-fields-of-an-object-type/33956/4 "2017-07-05T23:39:52Z")

</div>


