第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

為什么查詢不包含某個(gè)詞的記錄時(shí) must_not不生效呢?

為什么查詢不包含某個(gè)詞的記錄時(shí) must_not不生效呢?

慕斯王 2018-07-23 21:04:03
為什么must_not就不生效呢?mapping:"text_terms": {    "type": "nested",    "properties": {        "term": {            "type": "string",            "index": "not_analyzed"         },        "freq": {            "type": "integer"         }     } }數(shù)據(jù){ "text_terms" : [ { "term" : "aaa", "freq" : 1 }, { "term" : "bbb", "freq" : 1 }, { "term" : "ccc", "freq" : 1 } ] } { "text_terms" : [ { "term" : "aaa", "freq" : 1 }, { "term" : "西門子", "freq" : 1 }, { "term" : "ccc", "freq" : 1 } ] } { "text_terms" : [ { "term" : "ccc", "freq" : 1 }, { "term" : "西門子", "freq" : 1 }, { "term" : "ddd", "freq" : 1 } ] } { "text_terms" : [ { "term" : "ddd", "freq" : 1 }, { "term" : "eee", "freq" : 1 } ] }查詢包含西門子的記錄 沒有問題 能查出包含西門子的兩條記錄"query": { "nested": { "query": { "bool": { "must": [{ "term": { "text_terms.term": "西門子" } }] } }, "path": "text_terms" } }但是查詢不包含西門子的記錄時(shí) 就不生效了呢?"query": { "nested": { "query": { "bool": { "must_not": [{ "term": { "text_terms.term": "西門子" } }] } }, "path": "text_terms" } }怎么此時(shí)四條記錄都能查出來呢?
查看完整描述

1 回答

?
慕少森

TA貢獻(xiàn)2019條經(jīng)驗(yàn) 獲得超9個(gè)贊


添加第五條記錄

"text_terms" : [ { "term" : "西門子", "freq" : 1 } ]

must_not 查不出此條記錄來 于是知道原因

只要text_term中存在term不等于西門子的記錄 都能查出來 即使其中也有term等于西門子

正確的查詢方法

"query": { "bool":{ "must_not":{ "nested": {"path": "text_terms", "query": { "term": { "text_terms.term": "西門子" } } } } } }

must_not應(yīng)該放在nested外面

補(bǔ)充:

  • must_not 在 nested 內(nèi)部

curl 'http://localhost:9200/test/_validate/query?explain=true&pretty' -H 'Content-Type: application/json' -d'
{"query": { "nested": {  "path": "text_terms", "query": { "bool": { "must_not": [{ "term": { "text_terms.term": "西門子" } }] } } } }
}
'  "explanations" : [
    {      "index" : "test",
      "valid" : true,
      "explanation" : "ToParentBlockJoinQuery (+(-text_terms.term:西門子 +*:*) #_type:__text_terms)"
    }
  ]
  • must_notnested外部

curl 'http://localhost:9200/test/_validate/query?explain=true&pretty' -H 'Content-Type: application/json' -d'
{"query": { "bool":{ "must_not":{ "nested": {"path": "text_terms", "query": { "term": { "text_terms.term": "西門子" } } } } } }
}
'  "explanations" : [
    {      "index" : "test",
      "valid" : true,
      "explanation" : "+(-ToParentBlockJoinQuery (text_terms.term:西門子) +*:*) #DocValuesFieldExistsQuery [field=_primary_term]"
    }
  ]


查看完整回答
反對 回復(fù) 2018-07-29
  • 1 回答
  • 0 關(guān)注
  • 1557 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)