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

Trying to do "findAndModify" in ES
According to doc Update By Query API | Elasticsearch Guide [7.17] | Elastic

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

Could you share the output of:

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

What is the output of:

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

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