Term Query on Keyword type which is part of a completion context did not work

Hi community, I have a problem with a property named "hash" which is of type "keyword". This property is also used for a completion category context.

ElasticSearch Version: docker.elastic.co/elasticsearch/elasticsearch-oss:7.6.2

The mapping of the index is:

{
  "mappings": {
    "properties": {
      "hash": {
        "type": "keyword"
      },
      "value": {
        "type": "completion",
        "contexts": [
          {
            "name": "hash",
            "type": "category",
            "path": "hash"
          }
        ]
      }
    }
  }
}

The index contain this document:

{
   "_index":"values_completion",
   "_type":"_doc",
   "_id":"e044c078f773f973e441125dc0b61e4d",
   "_score":1.0,
   "_source":{
      "hash":"439ad864081de8cd6b28763b5c43566e",
      "value":{
         "input":[
            "92"
         ]
      }
   }
}

The query I am attempting to do is:

{
	"query": {
		"term": {
			"hash": "439ad864081de8cd6b28763b5c43566e"
		}
	},
	"size": 10
}

I got no results from ElasticSearch ...

{
  "took": 1,
  "timed_out": false,
  "_shards": {
    "total": 1,
    "successful": 1,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": {
      "value": 100,
      "relation": "eq"
    },
    "max_score": 2.4103107,
    "hits": []
  }
}

Is it possible that the keyword type is not indexed as keyword due to the completion context ?

Thanks you for your time :slight_smile:

Welcome!

It sounds like that your request actually returns 100 hits:

"total": {
  "value": 100,
  "relation": "eq"
},

What makes you think that it does not work?

Could you provide a full recreation script as described in About the Elasticsearch category. It will help to better understand what you are doing. Please, try to keep the example as simple as possible.

A full reproduction script will help readers to understand, reproduce and if needed fix your problem.

Okay you are right, I was manipulating the size in parameter URL and in the body. In addition in my code I was using the wrong index haha so the hash wasn't the same.

Thanks you

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