简体   繁体   中英

Multi-query match_phrase_prefix elasticsearch

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,

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
        }
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM