ES :有兩種常用查詢(xún)??
????????must? ?必須滿(mǎn)足查詢(xún)條件
????????should 非必須滿(mǎn)足查詢(xún)條件
?如果想實(shí)現(xiàn)類(lèi)似與mysql中的or 查詢(xún)效果,必須使用should查詢(xún)。但是shuold 會(huì)查詢(xún)出不滿(mǎn)足條件的數(shù)據(jù) ,這必須加一個(gè)屬性?"minimum_should_match": "1" 必須滿(mǎn)足should條件中的一個(gè)查詢(xún)條件 這樣就能達(dá)到 or查詢(xún)的結(jié)果了。
"minimum_should_match": "1" 這個(gè)屬性不能亂用,如果沒(méi)有should查詢(xún)的條件不要加個(gè)這個(gè)屬性
提供參考原生es查詢(xún)條件:文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-506558.html
{
"from": 0,
"size": 30,
"query": {
"bool": {
"must": [
{
"query_string": {
"query": "status:0",
"fields": [],
"type": "best_fields",
"default_operator": "or",
"max_determinized_states": 10000,
"enable_position_increments": true,
"fuzziness": "AUTO",
"fuzzy_prefix_length": 0,
"fuzzy_max_expansions": 50,
"phrase_slop": 0,
"analyze_wildcard": true,
"escape": false,
"auto_generate_synonyms_phrase_query": true,
"fuzzy_transpositions": true,
"boost": 1.0
}
},
{
"terms": {
"saleableRange": [
"0",
"2"
],
"boost": 1.0
}
},
{
"query_string": {
"query": "entity:Product",
"fields": [],
"type": "best_fields",
"default_operator": "or",
"max_determinized_states": 10000,
"enable_position_increments": true,
"fuzziness": "AUTO",
"fuzzy_prefix_length": 0,
"fuzzy_max_expansions": 50,
"phrase_slop": 0,
"escape": false,
"auto_generate_synonyms_phrase_query": true,
"fuzzy_transpositions": true,
"boost": 1.0
}
}
],
"should": [
{
"query_string": {
"query": "shortName.keyword:*1011838*",
"fields": [],
"type": "best_fields",
"default_operator": "or",
"max_determinized_states": 10000,
"enable_position_increments": true,
"fuzziness": "AUTO",
"fuzzy_prefix_length": 0,
"fuzzy_max_expansions": 50,
"phrase_slop": 0,
"analyze_wildcard": true,
"escape": false,
"auto_generate_synonyms_phrase_query": true,
"fuzzy_transpositions": true,
"boost": 1.0
}
},
{
"query_string": {
"query": "code.keyword:*1011838*",
"fields": [],
"type": "best_fields",
"default_operator": "or",
"max_determinized_states": 10000,
"enable_position_increments": true,
"fuzziness": "AUTO",
"fuzzy_prefix_length": 0,
"fuzzy_max_expansions": 50,
"phrase_slop": 0,
"analyze_wildcard": true,
"escape": false,
"auto_generate_synonyms_phrase_query": true,
"fuzzy_transpositions": true,
"boost": 1.0
}
}
],
"adjust_pure_negative": true,
"minimum_should_match": "1",
"boost": 1.0
}
},
"sort": [
{
"sortNum": {
"order": "desc"
}
}
]
}
這個(gè)查詢(xún)滿(mǎn)足的條件是?shortName的查詢(xún)條件 或 code 查詢(xún)條件的結(jié)果文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-506558.html
到了這里,關(guān)于ES 實(shí)現(xiàn)數(shù)據(jù)庫(kù)or查詢(xún)效果的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!