Search multiple fields using multiple text values

I work with address searching. and I want to search with two formats (multiple values) of an adress using multiple fields. adress is a text input not a keyword.

For example :
user_address = 88 South East Street Raeford, NC 28376
formated_address = 88 SE ST Raeford, NC 28376

and I want to search with theses two values using field_1 and field_2.

This appoach worked for specif value/keyword like ids. but didn't work for text values like address

{
  "query": {
    "match": {
      "id": {
        "query": "111111 22222",
        "operator": "or"
      }
    }
  }
}

I tried using bool with must , but did'nt work because must like AND , and if one is false, will return nothing ; something like this :

{
  "query": {
    "bool": {
      "must": [
        {"match": {"field_1": "88 South East Street Raeford, NC 28376"}},
        {"match": {"field_2": "88 SE ST Raeford, NC 28376"}}
      ]
    }
  }
}

I tried using should, but give me more results and not specific results, that exactly match the required solutions.

I know that we can use match_multiple with multiple fields. Can I use it for multiple values ? if yes, How ?

Please who has any ideas, how to fix this issues, or any out of boxes ideas.
Thanks.

Hi, try "should" clause of boolean query, not "must" clause. In addition, take care about the default minimum_should_match setting if you use the should clause with other clauses.

{
  "query": {
    "bool": {
      "should": [
        {"match": {"field_1": "88 South East Street Raeford, NC 28376"}},
        {"match": {"field_2": "88 SE ST Raeford, NC 28376"}}
      ]
    }
  }
}
1 Like

Hello,

Did you read about Disjunction max query? I think that can help you.

GET /_search
{
  "query": {
    "dis_max": {
      "queries": [
        { "term": { "title": "Quick pets" } },
        { "term": { "body": "Quick pets" } }
      ],
      "tie_breaker": 0.7
    }
  }
}

Documentation: Disjunction max query | Elasticsearch Guide [8.4] | Elastic

1 Like

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