# Check whether document returned is from a read or a write index

**URL:** <https://discuss.elastic.co/t/check-whether-document-returned-is-from-a-read-or-a-write-index/276133>\
**Category:** Elasticsearch\
**Created:** [June 16, 2021, 12:15pm UTC](https://discuss.elastic.co/t/check-whether-document-returned-is-from-a-read-or-a-write-index/276133 "2021-06-16T12:15:03Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Deepti](https://avatars.discourse-cdn.com/v4/letter/d/ee7513/32.png) [@Deepti](https://discuss.elastic.co/u/Deepti)\
**Post date:** [June 16, 2021, 12:15pm UTC](https://discuss.elastic.co/t/check-whether-document-returned-is-from-a-read-or-a-write-index/276133/1 "2021-06-16T12:15:03Z")

</div>

I have a requirement where I want to delete the documents which match the query but only if they are in the read index , if it is in a write index I don't want the documents to be deleted.  
Below query deletes irrespective of whether read or write index.  
Iam using the delete by query api

Post /(alias name)/\_delete\_by\_query  
{  
"query": {  
"term": {  
"id":"101"  
}  
},  
"max\_docs": 1,  
"sort": [  
{  
"dateField": {  
"order": "asc"  
}  
}  
]  
}.  
Can you please tel me know if the query can be changed in a way it deletes only from read index.

Thank you

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [June 16, 2021, 12:31pm UTC](https://discuss.elastic.co/t/check-whether-document-returned-is-from-a-read-or-a-write-index/276133/2 "2021-06-16T12:31:50Z")

</div>

I believe you would need to explicitly list the indices to delete from rather than using an alias that includes the current write index.

---

<div class="post-metadata">

**Author:** ![Deepti](https://avatars.discourse-cdn.com/v4/letter/d/ee7513/32.png) [@Deepti](https://discuss.elastic.co/u/Deepti)\
**Post date:** [June 16, 2021, 12:41pm UTC](https://discuss.elastic.co/t/check-whether-document-returned-is-from-a-read-or-a-write-index/276133/3 "2021-06-16T12:41:03Z")

</div>

There are numerous read index so , listing all would be a problem.  
Is there a way to exclude the write index as there is just one write index

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [June 16, 2021, 12:48pm UTC](https://discuss.elastic.co/t/check-whether-document-returned-is-from-a-read-or-a-write-index/276133/4 "2021-06-16T12:48:58Z")

</div>

No there is not.

---

<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 14, 2021, 12:49pm UTC](https://discuss.elastic.co/t/check-whether-document-returned-is-from-a-read-or-a-write-index/276133/5 "2021-07-14T12:49:19Z")

</div>

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