Query does not support [prefix]

When I post the following query, I got an error response

{"error":{"root_cause":[{"type":"parsing_exception","reason":"[prefix] query does not support [prefix]","line":1,"col":119}],"type":"parsing_exception","reason":"[prefix] query does not support [prefix]","line":1,"col":119},"status":400}

Here's my POST query:

{"from":0,"size":10,"sort":{"_score":"desc"},"query":{"bool":{"must":{"bool":{"should":[[{"prefix":{"title":{"prefix":"of","boost":"1.0"}}}],{"multi_match":{"query":"of","fields":["title^1.0"]}},{"query_string":{"query":"(\"of\")","fields":["title^1.0"]}}]}}}}}

How can I make this query work for my autocomplete search?

The error clearly states that prefix query does not support prefix parameter. You should replace prefix parameter of title field in the prefix query withvalue. So the query should be:

{
  "from": 0,
  "size": 10,
  "sort": {
    "_score": "desc"
  },
  "query": {
    "bool": {
      "must": {
        "bool": {
          "should": [
            [
              {
                "prefix": {
                  "title": {
                    "value": "of",
                    "boost": "1.0"
                  }
                }
              }
            ],
            {
              "multi_match": {
                "query": "of",
                "fields": [
                  "title^1.0"
                ]
              }
            },
            {
              "query_string": {
                "query": "(\"of\")",
                "fields": [
                  "title^1.0"
                ]
              }
            }
          ]
        }
      }
    }
  }
}

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