emarel
emarel

Reputation: 401

ElasticSearch: Show partial match for multi search even if one field does not match

I am currently trying to do a multi search query on first name, last name, and date of birth. I want the results to show a complete match for first, last, and dob but also show results if the first name and last name match but a different date of birth exists then what was queried on.

As of right now my code only returns a result if all three fields have exact matches

GET /account/data/_search
{
  "query": {
    "match": {
      "first": {
        "query": "Chris"
      }
    }
  },
  "query": {
    "match": {
      "last": {
        "query": "Johnson"
      }
    }
  },
  "query": {
    "match": {
      "dob": {
        "query": "10-10-1990"
      }
    }
  }
}

Upvotes: 1

Views: 509

Answers (1)

ChintanShah25
ChintanShah25

Reputation: 12672

This can be solved with simple bool query

{
  "query": {
    "bool": {
      "must": [
        {
          "match": {
            "first": "TEXT"
          }
        },
        {
          "match": {
            "last": "TEXT"
          }
        }
      ],
      "should": [
        {
          "match": {
            "dob": "TEXT"
          }
        }
      ]
    }
  }
}

Upvotes: 1

Related Questions