# How to check document consistent with current mapping?

**URL:** https://discuss.elastic.co/t/how-to-check-document-consistent-with-current-mapping/278387
**Category:** Elasticsearch
**Created:** [July 12, 2021, 7:57am UTC](https://discuss.elastic.co/t/how-to-check-document-consistent-with-current-mapping/278387 "2021-07-12T07:57:27Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![peter5](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/peter5/32/82412_2.png) [@peter5](https://discuss.elastic.co/u/peter5)
#### Post date: [July 12, 2021, 7:57am UTC](https://discuss.elastic.co/t/how-to-check-document-consistent-with-current-mapping/278387/1 "2021-07-12T07:57:27Z")

</div>

i need to know if document is matching current mapping or not (if not match i need to reindex) .  
eg, i change a field analyzer several times by update mapping . i need to know current document index status is identical to the lastest mapping .  
but i don't know which api i need to use . thanks .

---

<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 12, 2021, 8:09am UTC](https://discuss.elastic.co/t/how-to-check-document-consistent-with-current-mapping/278387/2 "2021-07-12T08:09:08Z")

</div>

please be more specific what 'consistent' means in your context - the question is impossible to answer otherwise

---

<div class="post-metadata">

### Author: ![peter5](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/peter5/32/82412_2.png) [@peter5](https://discuss.elastic.co/u/peter5)
#### Post date: [July 12, 2021, 8:14am UTC](https://discuss.elastic.co/t/how-to-check-document-consistent-with-current-mapping/278387/3 "2021-07-12T08:14:01Z")

</div>

thanks reply , i don't know if someone changed my index's mapping . so i need to know my index need reindex or not . eg , changed the field's analyzer .i just need a api to check like this logic (for each document in index , check if the document is same with the lastest index mapping , if not , i will use update\_by\_query to update this document )

---

<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 12, 2021, 8:29am UTC](https://discuss.elastic.co/t/how-to-check-document-consistent-with-current-mapping/278387/4 "2021-07-12T08:29:56Z")

</div>

If you updated the mapping (i.e. by adding a field), you could use the `exists` query... take a look at this example if it helps you

```auto
DELETE test

PUT test

PUT test/_doc/1
{ "key" : "value" }

PUT test/_mapping
{
  "properties": {
    "other" : { "type":"text"}
  }
}

PUT test/_doc/2
{ "other" : "value" }

GET test/_search
{
  "query": {
    "bool": {
      "must_not": [
        { "exists": { "field": "other"}}
      ]
    }
  }
}

```

---

<div class="post-metadata">

### Author: ![peter5](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/peter5/32/82412_2.png) [@peter5](https://discuss.elastic.co/u/peter5)
#### Post date: [July 12, 2021, 8:45am UTC](https://discuss.elastic.co/t/how-to-check-document-consistent-with-current-mapping/278387/5 "2021-07-12T08:45:12Z")

</div>

acturally i dont know which mapping setting changed since we in a team develop mode but i need to reindex documents according to latest mapping . but i don't want to reindex them all to save some time . (and i even don't know if the mapping really changed or not) .  
for my understanding the mapping is like "class" and the index document is the "object" , i need an api like java 's  
"object instanceof class"  
....

---

<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 12, 2021, 8:51am UTC](https://discuss.elastic.co/t/how-to-check-document-consistent-with-current-mapping/278387/6 "2021-07-12T08:51:59Z")

</div>

Something like that does not exist, as the concept of instances does not fully map. You could try the above search with any field though.

---

<div class="post-metadata">

### Author: ![peter5](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/peter5/32/82412_2.png) [@peter5](https://discuss.elastic.co/u/peter5)
#### Post date: [July 12, 2021, 9:00am UTC](https://discuss.elastic.co/t/how-to-check-document-consistent-with-current-mapping/278387/7 "2021-07-12T09:00:28Z")

</div>

ok thanks

---

<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 9, 2021, 9:00am UTC](https://discuss.elastic.co/t/how-to-check-document-consistent-with-current-mapping/278387/8 "2021-08-09T09:00:42Z")

</div>

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