1

I am working to match a 'term' to multi fields (or _all field) I want to do a fuzzy match on cross_fields but it is not supported. any ideas how to do it or any other ways to do it ?

query: {
  multi_match: {
    query: term,
    type: "cross_fields",
    fields: ['_all']
  }
}

when trying the solution here

ElasticSearch multi_match query over multiple fields with Fuzziness

I get this error

[parsing_exception] Fuziness not allowed for type [cross_fields], with { line=1 & col=128 }

elasticsearch version 5.0

edit: here is the query I am building

bool: {
       must: [
             {
             fuzzy: {
                     _all: term
                     }
             },
             {
             fuzzy: {
                    "location.country": country
                    }
             },
             {
             fuzzy: {
                    "location.city": city
                    }
             }
             ]
      }
Abdullah Alsigar
  • 1,236
  • 1
  • 12
  • 16

1 Answers1

1

cross_fields works by searching the term on your multiple fields. Since fuzziness isn't supported for cross_fields you have to write the query in a different way.

One possible is: implement your own "cross_fields" with shoulds and add there the fuzziness.

Say your term is: "term1 term2", you can split by word boundary (Regex \b) then should them in this form:

{
   {
    "query": {
        "bool": {
            "should": [{
                    "match": {
                        "field1": "term",
                        "fuzziness": 1
                    }
                },{
                    "match": {
                        "field1": "term",
                        "fuzziness": 1
                    }
                },{
                    "match": {
                        "field2": "term1",
                        "fuzziness": 1
                    }
                },{
                    "match": {
                        "field2": "term12",
                        "fuzziness": 1
                    }
                }
            ]
        }
    }
}
}

This is probably less the optimal if you have many fields, the query will become a cartesian product of the terms and fields.

Important note You're using _all field which is one field. which all other fields are indexed into. Maybe you don't even need cross_fields?

aclowkay
  • 3,577
  • 5
  • 35
  • 66
  • according to the doc , the should query will match even if only one in matching. https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-bool-query.html > If the bool query is a filter context or has neither must or filter then at least one of the should queries must match a document for it to match the bool query. – Abdullah Alsigar Sep 14 '17 at 03:11