Multi-“match-phrase” query in Elastic Search

Your first query is not really a valid JSON object because you use the same field name twice.

You can use a bool must or should query to match both OR one of the phrases:

    PUT phrase/doc/1
    {
      "text": "St Peter Fm some other text Cape Basin"
    }

    //Match BOTH
    GET phrase/_search
    {
      "query": {
        "bool": {
          "must": [
             {"match_phrase": {"text":  "St Peter Fm"}},
             {"match_phrase": {"text":  "Cape Basin"}}
          ]
        }
     }
    }

    //Match EITHER ONE
    GET phrase/_search
    {
      "query": {
        "bool": {
          "should": [
             {"match_phrase": {"text":  "St Peter Fm"}},
             {"match_phrase": {"text":  "Cape Basin"}}
          ]
        }
     }
    }

Leave a Comment