3

How do I pass a list as query string to match_phrase query?

This works:

{"match_phrase": {"requestParameters.bucketName": {"query": "xxx"}}},

This does not:

        {
            "match_phrase": {
                "requestParameters.bucketName": {
                    "query": [
                        "auditloggingnew2232",
                        "config-bucket-123",
                        "web-servers",
                        "esbck-essnap-1djjegwy9fvyl",
                        "tempexpo",
                    ]
                }
            }
        }
6
  • Have to tried using bool query ? Ref : stackoverflow.com/a/30020384/11774805 Commented Jul 25, 2020 at 17:24
  • My question is, does match_phrase supports list like this: {"match_phrase": {"text": ["St Peter Fm", "Cape Basin"]}} ? Something like multi_match but for search term instead of fields. Commented Jul 25, 2020 at 17:38
  • Using "query_string" is a good workaround. My question is why "match_phrase" does not support a list? Commented Jul 28, 2020 at 1:53
  • Why do you need match_phrase if you're only searching a single token? Commented Jul 28, 2020 at 5:55
  • 1
    I got that, but match_phrase is for matching tokens that follow each other. You're querying individual tokens, so the terms query would probably fit your need. Commented Jan 5, 2021 at 14:01

1 Answer 1

3
+100

match_phrase simply does not support multiple values.

You can either use a should query:

GET _search
{
  "query": {
    "bool": {
      "should": [
        {
          "match_phrase": {
            "requestParameters.bucketName": {
              "value": "auditloggingnew2232"
            }
          }
        },
        {
          "match_phrase": {
            "requestParameters.bucketName": {
              "value": "config-bucket-123"
            }
          }
        }
      ]
    },
    ...
  }
}

or, as @Val pointed out, a terms query:

{
  "query": {
    "terms": {
      "requestParameters.bucketName": [
        "auditloggingnew2232",
        "config-bucket-123",
        "web-servers",
        "esbck-essnap-1djjegwy9fvyl",
        "tempexpo"
      ]
    }
  }
}

that functions like an OR on exact terms.

I'm assuming that 1) the bucket names in question are unique and 2) that you're not looking for partial matches. If that's the case, plus if there are barely any analyzers set on the field bucketName, match_phrase may not even be needed! terms will do just fine. The difference between term and match_phrase queries is nicely explained here.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.