# Update by Query elastic on field type as Text - ES 7.17

**URL:** <https://discuss.elastic.co/t/update-by-query-elastic-on-field-type-as-text-es-7-17/299837>\
**Category:** Elasticsearch\
**Created:** [March 16, 2022, 8:15am UTC](https://discuss.elastic.co/t/update-by-query-elastic-on-field-type-as-text-es-7-17/299837 "2022-03-16T08:15:59Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![vitaly1233](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vitaly1233/32/80196_2.png) [@vitaly1233](https://discuss.elastic.co/u/vitaly1233)\
**Post date:** [March 16, 2022, 8:16am UTC](https://discuss.elastic.co/t/update-by-query-elastic-on-field-type-as-text-es-7-17/299837/1 "2022-03-16T08:16:00Z")

</div>

Trying to do "findAndModify" in ES  
According to doc [Update By Query API | Elasticsearch Guide [7.17] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/7.17/docs-update-by-query.html)

We have mapping as the following:

```
 {
  "dynamic_templates": [
    {
      "strings_as_keywords": {
        "match_mapping_type": "string",
        "mapping": {
          "type": "text",
          "analyzer": "autocomplete",
          "search_analyzer": "search_term_analyzer",
          "copy_to": "_all",
          "fields": {
            "keyword": {
              "type": "keyword",
              "normalizer": "lowercase_normalizer",
              "eager_global_ordinals" : true
            }
          }
        }
      }
    }
  ]
}

"analysis": {
    "normalizer": {
      "lowercase_normalizer": {
        "type": "custom",
        "filter": [
          "lowercase"
        ]
      }
    },
    "analyzer": {
      "autocomplete": {
        "tokenizer" : "keyword",
        "filter": [
          "lowercase"
        ]
      },
      "search_term_analyzer" : {
        "filter" : [
          "lowercase"
        ],
        "tokenizer" : "standard"
      }
    }
  }

```

Before update execute 2 queries on keyword as term (exact match) and Text  
we can see in both cases the result is the same:

```
http://10.2.0.243:9200/index/_count
 {
  "query": { 
    "match": {
       "fileName": "WithEmail.txt"
    }
  }
}

 http://10.2.0.243:9200/index/_count
 {
  "query": { 
    "match": {
       "fileName.keyword": "WithEmail.txt"
    }
  }
}
  result:
{
  "count": 10000,
  "_shards": {
    "total": 1,
    "successful": 1,
    "skipped": 0,
    "failed": 0
  }
}

```

Now doing query by update:

```
POST http://10.2.0.243:9200/index/_update_by_query 
{
  "query": { 
    "match": {
       "fileName": "WithEmail.txt"
    }
  },
	"script": {
    "source": "ctx._source.fileName = 'new_update_email.txt'"
  }
}

```

Query again:

```
http://10.2.0.243:9200/index/_count
 
  {
  "query": { 
    "match": {
       "fileName.keyword": "new_update_email.txt"
    }
  }
}

result (which is ok as expected):
{
  "count": 10000,
  "_shards": {
    "total": 1,
    "successful": 1,
    "skipped": 0,
    "failed": 0
  }
}

 http://10.2.0.243:9200/index/_count
  {
  "query": { 
    "match": {
       "fileName": "new_update_email.txt"
    }
  }
}

```

result no results at all: (why ???)

```
{
  "count": 0,
  "_shards": {
    "total": 1,
    "successful": 1,
    "skipped": 0,
    "failed": 0
  }
}

```

My question is why getting results only on term and not text.  
What i'm missing ?

Working with ES 7.17

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [March 16, 2022, 9:58am UTC](https://discuss.elastic.co/t/update-by-query-elastic-on-field-type-as-text-es-7-17/299837/2 "2022-03-16T09:58:47Z")

</div>

Could you share the output of:

```auto
GET index/_mapping

```

---

<div class="post-metadata">

**Author:** ![vitaly1233](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vitaly1233/32/80196_2.png) [@vitaly1233](https://discuss.elastic.co/u/vitaly1233)\
**Post date:** [March 16, 2022, 11:36am UTC](https://discuss.elastic.co/t/update-by-query-elastic-on-field-type-as-text-es-7-17/299837/3 "2022-03-16T11:36:31Z")

</div>

```
"fileName": {
      "type": "text",
      "fields": {
        "keyword": {
          "type": "keyword",
          "eager_global_ordinals": true,
          "normalizer": "lowercase_normalizer"
        }
      },
      "copy_to": [
        "_all"
      ],
      "analyzer": "autocomplete",
      "search_analyzer": "search_term_analyzer"
    },
```

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [March 17, 2022, 10:23am UTC](https://discuss.elastic.co/t/update-by-query-elastic-on-field-type-as-text-es-7-17/299837/4 "2022-03-17T10:23:36Z")

</div>

What is the output of:

```auto
GET /index/_analyze
{
  "analyzer" : "autocomplete",
  "text" : "new_update_email.txt"
}
GET /index/_analyze
{
  "analyzer" : "search_term_analyzer",
  "text" : "new_update_email.txt"
}

```

---

<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:** [April 14, 2022, 10:24am UTC](https://discuss.elastic.co/t/update-by-query-elastic-on-field-type-as-text-es-7-17/299837/5 "2022-04-14T10:24:22Z")

</div>

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