# Unable to UpdateByQuery via Java API when adding "sort" to existing field

**URL:** https://discuss.elastic.co/t/unable-to-updatebyquery-via-java-api-when-adding-sort-to-existing-field/117835
**Category:** Elasticsearch
**Created:** [January 31, 2018, 2:45pm UTC](https://discuss.elastic.co/t/unable-to-updatebyquery-via-java-api-when-adding-sort-to-existing-field/117835 "2018-01-31T14:45:39Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![luicir](https://avatars.discourse-cdn.com/v4/letter/l/c0e974/32.png) [@luicir](https://discuss.elastic.co/u/luicir)
#### Post date: [January 31, 2018, 2:45pm UTC](https://discuss.elastic.co/t/unable-to-updatebyquery-via-java-api-when-adding-sort-to-existing-field/117835/1 "2018-01-31T14:45:39Z")

</div>

I want to avoid reindexing all documents after a field mapping being changed from (excerpt from the template file):

```
   "subject": {
              "type": "string"
            },

```

to:

```
"subject": {
          "type": "string",
          "fields": {
            "sort": {
              "type": "string",
              "analyzer": "ducet_sort_subject"
            },
            "sortConversation": {
              "type": "string",
              "analyzer": "ducet_sort_subject_conversation"
            }
          }
        },

```

my java code latest version is the following:

```
PutMappingResponse putMappingResponse = client.admin().indices().preparePutMapping(indexName)
        .setSource("{\"properties\": {}}").setType("email").execute().actionGet();

      BulkIndexByScrollResponse bulkIndexByScrollResponse = INSTANCE.newRequestBuilder(client).source(indexName).get();

```

Please note that there is no unmappedType default, so if the mapping is not found, I'm expecting to see some error, (as it does without these new lines). Instead I get the results back also for unindexed documents, but the order is random.

I have also tried to add the mapping manually in the setSource above, but result didn't change.

In the documentation I read two statements that seem to be contrasting:

"The simplest usage of \_update\_by\_query just performs an update on every document in the index without changing the source. This is useful to pick up a new property or some other online mapping change."

and

"Templates are only applied at index creation time. Changing a template will have no impact on existing indices. When using the create index API, the settings/mappings defined as part of the create index call will take precedence over any matching settings/mappings defined in the template."

is it even possible to do what I want without reindexing?

---

<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: [February 28, 2018, 2:46pm UTC](https://discuss.elastic.co/t/unable-to-updatebyquery-via-java-api-when-adding-sort-to-existing-field/117835/2 "2018-02-28T14:46:24Z")

</div>

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