Getting exception while searching search as type field type

I have a requirement where I need to implement search recommendations and I have opted for the search as you type field. My existing mapping for the field was "text" and now I have changed it to "search_as_you_type" and reindex the index to get the updated mapping. While querying for the data I am getting below exception.

Mapping:

"properties": {
      "type": {
        "type": "keyword"
      },
      "title": {
        "type": "search_as_you_type",
        "store": true
      },

Request:

{
	"from": 0,
	"size": 10,
	"timeout": "5000ms",
	"query": {
		"bool": {
			"must": [{
				"bool": {
					"must": [{
						"bool": {
							"should": [ {
								"query_string": {
									"query": "Star",
									"default_field": "title",
									"fields": [],
									"type": "best_fields",
									"default_operator": "or",
									"max_determinized_states": 10000,
									"enable_position_increments": true,
									"fuzziness": "AUTO",
									"fuzzy_prefix_length": 0,
									"fuzzy_max_expansions": 50,
									"phrase_slop": 0,
									"analyze_wildcard": true,
									"escape": false,
									"auto_generate_synonyms_phrase_query": true,
									"fuzzy_transpositions": true,
									"boost": 2.0
								}
							}],
							"adjust_pure_negative": true,
							"minimum_should_match": "1",
							"boost": 1.0
						}
					}],
					"adjust_pure_negative": true,
					"boost": 1.0
				}
			}],
			"adjust_pure_negative": true,
			"boost": 1.0
		}
	}
}

Exception:

{
  "error" : {
    "root_cause" : [
      {
        "type" : "illegal_argument_exception",
        "reason" : "Fielddata is not supported on field [title] of type [search_as_you_type]"
      }
    ],
    "type" : "search_phase_execution_exception",
    "reason" : "all shards failed",
    "phase" : "query",
    "grouped" : true,
    "failed_shards" : [
      {
        "shard" : 0,
        "index" : "application",
        "node" : "V0bTylUqSXe025iSbyTpKw",
        "reason" : {
          "type" : "illegal_argument_exception",
          "reason" : "Fielddata is not supported on field [title] of type [search_as_you_type]"
        }
      }
    ],
    "caused_by" : {
      "type" : "illegal_argument_exception",
      "reason" : "Fielddata is not supported on field [title] of type [search_as_you_type]",
      "caused_by" : {
        "type" : "illegal_argument_exception",
        "reason" : "Fielddata is not supported on field [__doc_title] of type [search_as_you_type]"
      }
    }
  },
  "status" : 400
}

Please suggest what is wrong here??

Hi @Munish_Bhardwaj Welcome to the community!

I thought I had something for you but it was a typo my side

Usually that fieldata error is related to trying to do a terms search on a text type but you don't seem to be doing that...

Hmm ... more research needed from my side.. apologies.
I could not reproduce...

PUT discuss-my-index-000001
{
  "mappings": {
    "properties": {
      "my_field": {
        "type": "search_as_you_type"
      }
    }
  }
}

PUT discuss-my-index-000001/_doc/1?refresh
{
  "my_field": "quick brown fox jump lazy dog"
}

GET discuss-my-index-000001/_search
{
	"from": 0,
	"size": 10,
	"timeout": "5000ms",
	"query": {
		"bool": {
			"must": [{
				"bool": {
					"must": [{
						"bool": {
							"should": [ {
								"query_string": {
									"query": "Brown",
									"default_field": "my_field",
									"fields": [],
									"type": "best_fields",
									"default_operator": "or",
									"max_determinized_states": 10000,
									"enable_position_increments": true,
									"fuzziness": "AUTO",
									"fuzzy_prefix_length": 0,
									"fuzzy_max_expansions": 50,
									"phrase_slop": 0,
									"analyze_wildcard": true,
									"escape": false,
									"auto_generate_synonyms_phrase_query": true,
									"fuzzy_transpositions": true,
									"boost": 2.0
								}
							}],
							"adjust_pure_negative": true,
							"minimum_should_match": "1",
							"boost": 1.0
						}
					}],
					"adjust_pure_negative": true,
					"boost": 1.0
				}
			}],
			"adjust_pure_negative": true,
			"boost": 1.0
		}
	}
}

Results

{
  "took" : 1,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 1,
      "relation" : "eq"
    },
    "max_score" : 0.5753642,
    "hits" : [
      {
        "_index" : "discuss-my-index-000001",
        "_id" : "1",
        "_score" : 0.5753642,
        "_source" : {
          "my_field" : "quick brown fox jump lazy dog"
        }
      }
    ]
  }
}

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