elasticsearch 同一个条件多匹配值查询

terms实现多值匹配channelCode.code是个list

GET cms_45/_search { "query": { "nested": { "path": "channelCode", "query": { "terms": { "channelCode.code": [ "0", "9999000011" ] } } } } }

should实现多值同时匹配 "minimum_should_match": "1"

GET cms_45/_search { "from": 0, "size": 30, "query": { "bool": { "filter": [{ "bool": { "should": [{ "nested": { "query": { "match": { "channelCode.code": { "query": 0, "operator": "OR", "prefix_length": 0, "max_expansions": 50, "fuzzy_transpositions": true, "lenient": false, "zero_terms_query": "NONE", "auto_generate_synonyms_phrase_query": true, "boost": 1.0 } } }, "path": "channelCode", "ignore_unmapped": false, "score_mode": "none", "boost": 1.0 } }, { "nested": { "query": { "match": { "channelCode.code": { "query": "9999000011", "operator": "OR", "prefix_length": 0, "max_expansions": 50, "fuzzy_transpositions": true, "lenient": false, "zero_terms_query": "NONE", "auto_generate_synonyms_phrase_query": true, "boost": 1.0 } } }, "path": "channelCode", "ignore_unmapped": false, "score_mode": "none", "boost": 1.0 } }], "adjust_pure_negative": true, "minimum_should_match": "1", "boost": 1.0 } }], "adjust_pure_negative": true, "boost": 1.0 } }, "sort": [{ "searchPriority": { "order": "desc" } }, { "_score": { "order": "desc" } }, { "year.keyword": { "order": "desc" } }, { "timestamp": { "order": "desc" } }] }

经验分享 程序员 微信小程序 职场和发展