0

I would like to query 2 different prefixes for the same field. The code below works exactly how I would like it to when working with on field:

GET  /logstash-*/_search
{
    "query": {
        "match_phrase_prefix" : {
            "type" : {
                "query" : "job-source"
            }
        }
    }
}

I could not find in the docs how to do this with two queries (I found how to search in multiple fields). I have tried a boolean should and the snippet below but both are not giving me the results I am looking for.

GET  /logstash-*/_search
{
    "query": {
        "match_phrase_prefix" : {
            "type" : {
                "query" : ["job-source","job-find"]
            }
        }
    }
}

How do I query for only documents that have type:job-source or type:job-find as the prefix?

Thank you in advance,

1 Answer 1

1

You can combine two match_phrase_prefix queries using should and set minimum_should_match to 1.

Sample Query:

{
    "query":
    {
        "bool":
        {
            "should": [
            {
                "match_phrase_prefix":
                {
                    "type": "job-source"
                }
            },
            {
                "match_phrase_prefix":
                {
                    "type": "job-find"
                }
            }],
            "minimum_should_match": 1
        }
    }
}
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.