# Only speficied fields

**URL:** <https://discuss.elastic.co/t/only-speficied-fields/86788>\
**Category:** Elasticsearch\
**Created:** [May 23, 2017, 9:49am UTC](https://discuss.elastic.co/t/only-speficied-fields/86788 "2017-05-23T09:49:34Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![Giuseppe\_Merlo](https://avatars.discourse-cdn.com/v4/letter/g/a88e57/32.png) [@Giuseppe\_Merlo](https://discuss.elastic.co/u/Giuseppe_Merlo)\
**Post date:** [May 23, 2017, 9:49am UTC](https://discuss.elastic.co/t/only-speficied-fields/86788/1 "2017-05-23T09:49:34Z")

</div>

Hi forum!

There is a way that make me able to insert into an index only specified fields?

Here is an example:

I create the Anime index with only name field, this is my Anime.mapping file:

```
{
    "properties": {
        "name": {
            "index": "not_analyzed",
            "type": "string"
        }
    }
}

```

If i try to put a document like this:

```
 { 
     "name": "One Piece"
    }

```

then the result has to be ok.

Instead, if i try to put a document looks like:

```
     { 
         "name": "One Piece",
         "author": "Eichiro Oda"
        }

```

Elasticsearch must return error.

Thank you for helping me!

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [May 23, 2017, 10:01am UTC](https://discuss.elastic.co/t/only-speficied-fields/86788/2 "2017-05-23T10:01:16Z")

</div>

What is the error ?

---

<div class="post-metadata">

**Author:** ![Giuseppe\_Merlo](https://avatars.discourse-cdn.com/v4/letter/g/a88e57/32.png) [@Giuseppe\_Merlo](https://discuss.elastic.co/u/Giuseppe_Merlo)\
**Post date:** [May 23, 2017, 10:03am UTC](https://discuss.elastic.co/t/only-speficied-fields/86788/3 "2017-05-23T10:03:28Z")

</div>

There isn't an error. I want that i can't insert other fields except for name.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [May 23, 2017, 10:17am UTC](https://discuss.elastic.co/t/only-speficied-fields/86788/4 "2017-05-23T10:17:59Z")

</div>

You can change the mapping to use strict dynamic mapping

[https://www.elastic.co/guide/en/elasticsearch/reference/5.4/dynamic.html](https://www.elastic.co/guide/en/elasticsearch/reference/5.4/dynamic.html)

---

<div class="post-metadata">

**Author:** ![Giuseppe\_Merlo](https://avatars.discourse-cdn.com/v4/letter/g/a88e57/32.png) [@Giuseppe\_Merlo](https://discuss.elastic.co/u/Giuseppe_Merlo)\
**Post date:** [May 23, 2017, 10:40am UTC](https://discuss.elastic.co/t/only-speficied-fields/86788/5 "2017-05-23T10:40:33Z")

</div>

That not works.

This is my Anime.mapping file:

```
{
        "mappings": {
        "my_type": {
          "dynamic": false, 
          "properties": {
            "user": { 
    	"dynamic": false,
              "properties": {
                "name": {
                  "type": "string"
                }
        }
       }
      }
     }
    }
   }

```

My first Put:  
`curl -XPUT 'http://localhost:9200/anime/user/1' -d '{"name":"OP"}'`

My second Put:  
`curl -XPUT 'http://localhost:9200/anime/user/9' -d '{"name":"OP", "author": "er"}'`

Both request are successful.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [May 23, 2017, 11:00am UTC](https://discuss.elastic.co/t/only-speficied-fields/86788/6 "2017-05-23T11:00:12Z")

</div>

I said `strict`.

---

<div class="post-metadata">

**Author:** ![Giuseppe\_Merlo](https://avatars.discourse-cdn.com/v4/letter/g/a88e57/32.png) [@Giuseppe\_Merlo](https://discuss.elastic.co/u/Giuseppe_Merlo)\
**Post date:** [May 23, 2017, 11:04am UTC](https://discuss.elastic.co/t/only-speficied-fields/86788/7 "2017-05-23T11:04:09Z")

</div>

Sorry, i didn't see it.  
But It has the same behavior. 😔

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [May 23, 2017, 1:15pm UTC](https://discuss.elastic.co/t/only-speficied-fields/86788/8 "2017-05-23T13:15:40Z")

</div>

It works for me:

```auto
DELETE test
PUT test
{
  "mappings": {
    "doc": {
      "dynamic": "strict",
      "properties": {
        "user": {
          "type": "text"
        }
      }
    }
  }
}
PUT test/doc/1
{
  "foo": "bar"
}

```

Gives:

```auto
{
  "error": {
    "root_cause": [
      {
        "type": "strict_dynamic_mapping_exception",
        "reason": "mapping set to strict, dynamic introduction of [foo] within [doc] is not allowed"
      }
    ],
    "type": "strict_dynamic_mapping_exception",
    "reason": "mapping set to strict, dynamic introduction of [foo] within [doc] is not allowed"
  },
  "status": 400
}

```

---

<div class="post-metadata">

**Author:** ![Giuseppe\_Merlo](https://avatars.discourse-cdn.com/v4/letter/g/a88e57/32.png) [@Giuseppe\_Merlo](https://discuss.elastic.co/u/Giuseppe_Merlo)\
**Post date:** [May 23, 2017, 1:41pm UTC](https://discuss.elastic.co/t/only-speficied-fields/86788/9 "2017-05-23T13:41:25Z")

</div>

What is your elasticsearch.yml configuration? Do you change anything on it?

---

<div class="post-metadata">

**Author:** ![Giuseppe\_Merlo](https://avatars.discourse-cdn.com/v4/letter/g/a88e57/32.png) [@Giuseppe\_Merlo](https://discuss.elastic.co/u/Giuseppe_Merlo)\
**Post date:** [May 23, 2017, 2:15pm UTC](https://discuss.elastic.co/t/only-speficied-fields/86788/10 "2017-05-23T14:15:23Z")

</div>

UPDATE:

it works, but only for field changes.

This is my Anime.mapping file:

```
{
  "mappings": {
    "doc": {
      "dynamic": "strict",
      "properties": {
        "name": {
          "type": "string"
        }
      }
    }
  }
}

```

if i try to put this:

```
curl -XPUT 'http://localhost:9200/anime/doc/1' -d '{"name":"OP"}'

```

it works.

if i try to put this:

```
curl -XPUT 'http://localhost:9200/anime/doc/1' -d '{"foo":"OP"}'

```

it gets the error:

```
{
  "error": {
    "root_cause": [
      {
        "type": "strict_dynamic_mapping_exception",
        "reason": "mapping set to strict, dynamic introduction of [foo] within [doc] is not allowed"
      }
    ],
    "type": "strict_dynamic_mapping_exception",
    "reason": "mapping set to strict, dynamic introduction of [foo] within [doc] is not allowed"
  },
  "status": 400
}

```

Correct! But if i try to put this:

`curl -XPUT 'http://localhost:9200/anime/user/9' -d '{"name":"OP", "author": "er"}'`

it works too. I want in this case an error like before.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [May 23, 2017, 2:41pm UTC](https://discuss.elastic.co/t/only-speficied-fields/86788/11 "2017-05-23T14:41:15Z")

</div>

Nope.

```auto
PUT test/doc/9
{
  "name": "OP",
  "author": "er"
}

```

gives:

```auto
{
  "error": {
    "root_cause": [
      {
        "type": "strict_dynamic_mapping_exception",
        "reason": "mapping set to strict, dynamic introduction of [name] within [doc] is not allowed"
      }
    ],
    "type": "strict_dynamic_mapping_exception",
    "reason": "mapping set to strict, dynamic introduction of [name] within [doc] is not allowed"
  },
  "status": 400
}

```

---

<div class="post-metadata">

**Author:** ![Giuseppe\_Merlo](https://avatars.discourse-cdn.com/v4/letter/g/a88e57/32.png) [@Giuseppe\_Merlo](https://discuss.elastic.co/u/Giuseppe_Merlo)\
**Post date:** [May 23, 2017, 2:45pm UTC](https://discuss.elastic.co/t/only-speficied-fields/86788/12 "2017-05-23T14:45:57Z")

</div>

Did you have changed your mapping in order to use "name"?  
If not, can you try with "foo" instead of "name", please? Thank you so much.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [May 23, 2017, 3:35pm UTC](https://discuss.elastic.co/t/only-speficied-fields/86788/13 "2017-05-23T15:35:16Z")

</div>

```auto
DELETE test
PUT test
{
  "mappings": {
    "doc": {
      "dynamic": "strict",
      "properties": {
        "name": {
          "type": "text"
        }
      }
    }
  }
}
PUT test/doc/1
{
  "name": "OP",
  "author": "er"
}

```

gives

```auto
{
  "error": {
    "root_cause": [
      {
        "type": "strict_dynamic_mapping_exception",
        "reason": "mapping set to strict, dynamic introduction of [author] within [doc] is not allowed"
      }
    ],
    "type": "strict_dynamic_mapping_exception",
    "reason": "mapping set to strict, dynamic introduction of [author] within [doc] is not allowed"
  },
  "status": 400
}

```

If you can't reproduce it please share a full formatted script as I just did so I can check it.

---

<div class="post-metadata">

**Author:** ![Giuseppe\_Merlo](https://avatars.discourse-cdn.com/v4/letter/g/a88e57/32.png) [@Giuseppe\_Merlo](https://discuss.elastic.co/u/Giuseppe_Merlo)\
**Post date:** [May 24, 2017, 7:20am UTC](https://discuss.elastic.co/t/only-speficied-fields/86788/14 "2017-05-24T07:20:28Z")

</div>

Now it seems to work! I follow your steps and they work fine! Thank you for your patience!

---

<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:** [June 21, 2017, 7:20am UTC](https://discuss.elastic.co/t/only-speficied-fields/86788/15 "2017-06-21T07:20:32Z")

</div>

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