# How do I set the mandatory insertion of all fields when creating a document

**URL:** <https://discuss.elastic.co/t/how-do-i-set-the-mandatory-insertion-of-all-fields-when-creating-a-document/279849>\
**Category:** Elasticsearch\
**Created:** [July 28, 2021, 11:41am UTC](https://discuss.elastic.co/t/how-do-i-set-the-mandatory-insertion-of-all-fields-when-creating-a-document/279849 "2021-07-28T11:41:01Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![myly-zyr](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/myly-zyr/32/92250_2.png) [@myly-zyr](https://discuss.elastic.co/u/myly-zyr)\
**Post date:** [July 28, 2021, 11:41am UTC](https://discuss.elastic.co/t/how-do-i-set-the-mandatory-insertion-of-all-fields-when-creating-a-document/279849/1 "2021-07-28T11:41:01Z")

</div>

In our project, a program does not insert all fields when creating a document, and other programs will report errors when reading the document. I want to set elasticsearch to insert all fields when creating a document. How should I set it, or do you have other solutions

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [July 28, 2021, 11:24pm UTC](https://discuss.elastic.co/t/how-do-i-set-the-mandatory-insertion-of-all-fields-when-creating-a-document/279849/2 "2021-07-28T23:24:01Z")

</div>

Welcome to our community! 😃

What do you want Elasticsearch to insert into these fields? Because what is likely happening is that the document will have the field, but a null value, which your app might not like.

---

<div class="post-metadata">

**Author:** ![myly-zyr](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/myly-zyr/32/92250_2.png) [@myly-zyr](https://discuss.elastic.co/u/myly-zyr)\
**Post date:** [July 29, 2021, 1:37am UTC](https://discuss.elastic.co/t/how-do-i-set-the-mandatory-insertion-of-all-fields-when-creating-a-document/279849/4 "2021-07-29T01:37:32Z")

</div>

![es](https://us1.discourse-cdn.com/elastic/original/3X/b/2/b2871fff581d3ef511c519ed8904629cbf4db3cd.png)  
For example, the index in the picture has five fields. When I want to create a document, I must force to fill in the values of five fields instead of three or two fields. Can I realize it

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [July 29, 2021, 3:19am UTC](https://discuss.elastic.co/t/how-do-i-set-the-mandatory-insertion-of-all-fields-when-creating-a-document/279849/5 "2021-07-29T03:19:28Z")

</div>

Please don't post pictures of text or code. They are difficult to read, impossible to search and replicate (if it's code), and some people may not be even able to see them 🙂

Have you seen [null\_value | Elasticsearch Guide [7.13] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/current/null-value.html)?

---

<div class="post-metadata">

**Author:** ![stephenb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephenb/32/40856_2.png) [@stephenb](https://discuss.elastic.co/u/stephenb)\
**Post date:** [July 29, 2021, 4:01am UTC](https://discuss.elastic.co/t/how-do-i-set-the-mandatory-insertion-of-all-fields-when-creating-a-document/279849/6 "2021-07-29T04:01:06Z")

</div>

You can use an [Ingest Pipeline](https://www.elastic.co/guide/en/elasticsearch/reference/current/ingest.html) and test if the values exist and if they don't set your default value(s)

---

<div class="post-metadata">

**Author:** ![myly-zyr](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/myly-zyr/32/92250_2.png) [@myly-zyr](https://discuss.elastic.co/u/myly-zyr)\
**Post date:** [July 29, 2021, 6:32am UTC](https://discuss.elastic.co/t/how-do-i-set-the-mandatory-insertion-of-all-fields-when-creating-a-document/279849/8 "2021-07-29T06:32:21Z")

</div>

I'm really sorry. I don't know the community rules. I republished the code. Is that ok?  
Let me describe my problem again. Please help me look at it. For example, the code I published created a test index, which contains five fields

```auto
PUT test 
{
  "settings": {
    "index": {
      "max_result_window": "100000000"
    }
  },
  "mappings": {
    "warnone": {
      "dynamic": "strict",
      "properties": {
        "sex": {
          "index": "not_analyzed",
          "type": "string"
        },
        "phone": {
          "index": "not_analyzed",
          "type": "string"
        },
        "email": {
          "index": "not_analyzed",
          "type": "string"
        },
        "name": {
          "index": "not_analyzed",
          "type": "string"
        },
        "age": {
          "index": "not_analyzed",
          "type": "string"
        }
      }
    }
  }
}

```

Now I create a three field document for the test index, which is feasible, but I don't want to allow this way to create documents

```auto
POST test/warnone
{
  "name": "Tom",
  "age": "eighteen",
  "sex": "man"
}

```

I want to include all the fields of the index when creating the document, otherwise the document cannot be created successfully

```auto
POST test/warnone
{
  "name": "Tom",
  "age": "eighteen",
  "sex": "man",
  "email": "123456@gmail.com",
  "phone": "1234567890"
}

```

I want to force the document to include all fields of the index when creating the document. How do I set it? In addition, my elastic search is version 2.4.0. For personal reasons, version 7.13 cannot be updated at present.

---

<div class="post-metadata">

**Author:** ![myly-zyr](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/myly-zyr/32/92250_2.png) [@myly-zyr](https://discuss.elastic.co/u/myly-zyr)\
**Post date:** [July 29, 2021, 6:33am UTC](https://discuss.elastic.co/t/how-do-i-set-the-mandatory-insertion-of-all-fields-when-creating-a-document/279849/9 "2021-07-29T06:33:34Z")

</div>

Thank you for your reply, but my version is 2.4.0. Is there any feasible solution

---

<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:** [July 29, 2021, 8:03am UTC](https://discuss.elastic.co/t/how-do-i-set-the-mandatory-insertion-of-all-fields-when-creating-a-document/279849/10 "2021-07-29T08:03:57Z")

</div>

Then you need to check it in your client application, unless you upgrade to a version supporting ingest pipelines.

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [July 30, 2021, 12:56am UTC](https://discuss.elastic.co/t/how-do-i-set-the-mandatory-insertion-of-all-fields-when-creating-a-document/279849/11 "2021-07-30T00:56:54Z")

</div>

2.4 has been [EOL](https://www.elastic.co/support/eol) for a long, long time. Please upgrade.

---

<div class="post-metadata">

**Author:** ![myly-zyr](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/myly-zyr/32/92250_2.png) [@myly-zyr](https://discuss.elastic.co/u/myly-zyr)\
**Post date:** [July 30, 2021, 5:39am UTC](https://discuss.elastic.co/t/how-do-i-set-the-mandatory-insertion-of-all-fields-when-creating-a-document/279849/12 "2021-07-30T05:39:24Z")

</div>

So if I want to realize my idea, I have to upgrade, right

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [July 30, 2021, 6:00am UTC](https://discuss.elastic.co/t/how-do-i-set-the-mandatory-insertion-of-all-fields-when-creating-a-document/279849/13 "2021-07-30T06:00:30Z")

</div>

2.4 has [null\_value | Elasticsearch Guide [2.4] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/2.4/null-value.html), otherwise you need to handle it all in your own code.

---

<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:** [August 27, 2021, 6:01am UTC](https://discuss.elastic.co/t/how-do-i-set-the-mandatory-insertion-of-all-fields-when-creating-a-document/279849/14 "2021-08-27T06:01:26Z")

</div>

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