简体   繁体   中英

elasticsearch query_string and term search syntax

I would like to search for query_string that contains Bob and an Industry_Type_ID of either 8 OR 9 .

I am getting a parse error: Parse Failure [No parser for element [Industry_Type_ID]]

{
    "query" : {
        "query_string":{"query":"Bob"},
        "terms" : {
            "Industry_Type_ID" : [ "8", "9" ],
            "minimum_match" : 1
        }
    }
}

I am sure I am missing something obvious.

You can do it using bool query with two must clauses:

{
    "query" : {
        "bool" : {
            "must" : [
                {
                    "query_string":{"query":"Bob"}
                },
                {
                    "terms" : {
                        "Industry_Type_ID" : [ "8", "9" ],
                        "minimum_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