Need example for match query with fuzziness


(nolka) #1

Hi!
A have 2 records in type "authors", and use elasticsearch_dsl to perform queries to es.
Now i want to find record in type authors with first_name like "danil".
In index i have this recordm but first_name in it == Donil.

I try to query record from ES using this DSL

{
    "query": {
        "match": {
            "first_name": "Danil",
            "fuzziness": 2
        }
    }
}

but got exception in es:

{
  "error": {
    "root_cause": [
      {
        "type": "query_parsing_exception",
        "reason": "[match] query parsed in simplified form, with direct field name, but included more options than just the field name, possibly use its 'options' form, with 'query' element?",
        "index": "delphi",
        "line": 4,
        "col": 34
      }
    ],
    "type": "search_phase_execution_exception",
    "reason": "all shards failed",
    "phase": "query",
    "grouped": true,
    "failed_shards": [
      {
        "shard": 0,
        "index": "delphi",
        "node": "QEfmrg55TNyUkiCs7ja8hg",
        "reason": {
          "type": "query_parsing_exception",
          "reason": "[match] query parsed in simplified form, with direct field name, but included more options than just the field name, possibly use its 'options' form, with 'query' element?",
          "index": "delphi",
          "line": 4,
          "col": 34
        }
      }
    ]
  },
  "status": 400
}

What i'm doing wrong?


(nolka) #2

Got it!
The solution is:

   {
        "query": {
            "bool": {
                "must": [ 
                    {
                        "match": {
                            "first_name": {
                                "query": "danil",
                                "fuzziness": 2
                            }
                        }
                    }
                ]
            }
        }
    }

(Isabel Drost-Fromm) #3

This pretty much states what you are supposed to do instead. The following example in the docs might help you:

https://www.elastic.co/guide/en/elasticsearch/guide/current/fuzzy-match-query.html#fuzzy-match-query

Hope this helps,
Isabel


(system) #4