0

I have a fuzzy query with customized AUTO:10,20 fuzziness value.

{
"query": {
 "match": {
   "name": {
     "query": "nike",
     "fuzziness": "AUTO:10,20"
   }
 }
}
}

How to convert it to a query_string query? I tried nike~AUTO:10,20 but it is not working.

2 Answers 2

2

It's possible with query_strng as well, let me show using the same example as OP provided, both match_query provided by OP matches and query_string fetches the same document with same score.

And according to this and this ES docs, Elasticsearch supports AUTO:10,20 format, which is shown in my example as well.

Also

Index mapping

{
    "mappings": {
        "properties": {
            "name": {
                "type": "text"
            }
        }
    }
}

Index some doc

{
   "name" : "nike"
}

Search query using match with fuzziness

{
"query": {
 "match": {
   "name": {
     "query": "nike",
     "fuzziness": "AUTO:10,20"
   }
 }
}
}

And result

"hits": [
         {
            "_index": "so-query",
            "_type": "_doc",
            "_id": "1",
            "_score": 0.9808292,
            "_source": {
               "name": "nike"
            }
         }
      ]

Query_string with fuzziness

{
    "query": {
        "query_string": {
            "fields": ["name"],
            "query": "nike",
            "fuzziness": "AUTO:10,20"
        }
    }
}

And result

 "hits": [
         {
            "_index": "so-query",
            "_type": "_doc",
            "_id": "1",
            "_score": 0.9808292,
            "_source": {
               "name": "nike"
            }
         }
      ]
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for the answer! I actually want the solution of achieving this in single sentence like nike~1. @Daniel Schneiter replied it is not possible.
This is because I'm using AWS Neptune Full-Text Search (docs.aws.amazon.com/neptune/latest/userguide/…) solution. This solution only supports queries in Lucene syntax.
1

Lucene syntax only allows you to specify "fuzziness" with the tilde symbol "~", optionally followed by 0, 1 or 2 to indicate the edit distance.

Elasticsearch Query DSL supports a configurable special value for AUTO which then is used to build the proper Lucene query.

You would need to implement that logic on your application side, by evaluating the desired edit distance based on the length of your search term and then use <searchTerm>~<editDistance> in your query_string-query.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.