# Update document structure without duplication

**URL:** <https://discuss.elastic.co/t/update-document-structure-without-duplication/315244>\
**Category:** Logstash\
**Created:** [September 27, 2022, 9:27am UTC](https://discuss.elastic.co/t/update-document-structure-without-duplication/315244 "2022-09-27T09:27:26Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![reed](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/reed/32/122863_2.png) [@reed](https://discuss.elastic.co/u/reed)\
**Post date:** [September 27, 2022, 9:27am UTC](https://discuss.elastic.co/t/update-document-structure-without-duplication/315244/1 "2022-09-27T09:27:26Z")

</div>

Hi all,

I need to read alla index documents and for all add a new field with default value, my code is this:

```auto
input {
	elasticsearch {
	hosts => ["http://myelastic:9200"]
	index => "myindex-txt"
	user => aaa
	password	=> aaa
	}
}

filter {

	mutate {
	add_field => { "my_flag"	=> "N" }
	}
}

```

now in output if I try the "elasticsearch" plugin the result is the duplication of the documents, but if I try \_update\_by\_query the document is modified.  
The problem with my \_update\_by\_query is that query part match only a subset of my documents.  
I need something like this:

output {

if [a\_field] != "1" add the field ( mutate ) with default value

if [a\_field] != "2" add the field with "Y" value

}

Please help!

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:** [October 25, 2022, 9:27am UTC](https://discuss.elastic.co/t/update-document-structure-without-duplication/315244/2 "2022-10-25T09:27:37Z")

</div>

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