0

I am creating an index in elasticsearch and i want the ability to search across multiple fields i.e. have those fields be treated as one big search field. I've done some researching a came across 2 different ways to do this:

  1. The first is with cross_fields multi-match query. This allows for searching across multiple fields as one big field with the ability to boost certain fields. But does not allow for fuzziness to be added.

  2. Using copy_to I can copy fields to an 'all' field so that all the searchable terms are in one big field. This allows for fuzzy search but then does not allow me to boost by specific fields

Is there another cross_fields or search option i'm unaware of that will allow for me to fuzzy search as well as boost by a specific field?

1 Answers1

0

I think you could add fussiness to multi match. But it will be applied to all fields. Find an example below with boost and fuzziness

GET /my_index/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "multi_match": {
            "query": "bjorn borg schoenen",
            "fields": [
              "title^5.0",
              "brand^2.0"
            ],
            "type": "best_fields",
            "operator": "and",
            "fuzziness": "auto"
          }
        }
      ]
    }
  }
}

If you want to be more granular, you can use a boolean query with should and a minimum should match:

 {
      "query": {
        "bool": {
          "should": [
            {
              "match": {
                "brand": {
                  "query": "my query",
                  "fuzziness": "auto",
                  "boost": 2
                }
              }
            },
            {
              "match": {
                "title": {
                  "query": "my query",
                  "fuzziness": "auto",
                  "boost": 5
                }
              }
            }
          ],
          "minimum_should_match": 1
        }
      }
    }

And if the query become to complicated, I can suggest you to use a search template to keep integration easy on the app side: https://www.elastic.co/guide/en/elasticsearch/reference/current/search-template.html

Jaycreation
  • 2,029
  • 1
  • 15
  • 30
  • This would work if i wanted to search for one field OR the other in my query. For example if the fields were first name and last name and did a search for "Steve" or "Jobs" your solution would work. However if i searched for "Steve Jobs" multi_match best_fields would not work – Michael Mincone Aug 18 '20 at 13:13
  • Ok I understand what you mean, sorry I miss this detail. Your issue looks similar to this : https://stackoverflow.com/questions/23916180/elasticsearch-cross-fields-multi-match-with-fuzzy-search. The answer of SarZ should be your solution. Keep the multi_match with cross_field and do the fuzziness at the ingest time : - Ngrams allow you to do part of what you need for fuzziness at the ingest time. - Or you can use a phonetic field mapping to have a more aggressive fuzziness on ingest time https://www.elastic.co/guide/en/elasticsearch/plugins/current/analysis-phonetic.html – Jaycreation Aug 18 '20 at 13:41