No results when searching by a null value

I'm trying to fill some value for an autocomplete search box and I had this old code (from Elasticsearch 1.5) and I want to implement it into Elasticsearch 7.16

When I use this sentence

curl -H 'Content-Type: application/json' -XGET localhost:9200/bne8/_search?pretty -d '{
  "suggest": {
    "bne_suggest": {
      "text": "*san*",
      "completion": {
        "field": "label_ac",
        "size": 20,
        "contexts": {
          "type": "null"
        }
      }
    }
  }
}'

I get this:

{
  "took" : 3,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 0,
      "relation" : "eq"
    },
    "max_score" : null,
    "hits" : [ ]
  },
  "suggest" : {
    "bne_suggest" : [
      {
        "text" : "*san*",
        "offset" : 0,
        "length" : 5,
        "options" : [ ]
      }
    ]
  }
}

When I changed the "type" : "null" to an actual value (for example "cars"), I get at least 20 hits.

My issue is:

How can I rewrite this code to make get all the possible hits without an explicit type (instead of having just "cars", having "cars", "bikes", "planes"....)

I tried with "type" : "*" but doesn't work.

I'm new here and with Elasticsearch, so my apologizes if I write or do something wrong.

The mapping from "label_ac"

"label_ac" : {
          "type" : "completion",
          "analyzer" : "default",
          "preserve_separators" : true,
          "preserve_position_increments" : true,
          "max_input_length" : 50,
          "contexts" : [
            {
              "name" : "type",
              "type" : "CATEGORY",
              "path" : "@type"
            }
          ]
        }

@type field is a text

It was the most silly thing, so, reviewing the old code I realized that I had a 'default' field with values, so I change the "null" with that array and its working.

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