(1)bool:must,must_not,should,組合多個過濾條件 (2)bool可以嵌套 (3)相當於SQL中的多個and條件:當你把搜索語法學好了以后,基本可以實現部分常用的sql語法對應的功能 補充,在kibana中一般filter沒有只能提示了。可以先在query 直接寫。
should 當一個條件是是必須含有,兩個條件是滿足一個即可。綜合前兩句是,至少滿足一個條件即可。
GET /forum/article/_search { "query": { "constant_score": { "filter": { "bool": { "should": [ { "term": { "postDate": "2017-01-01" } }, { "term": { "articleID": "XHDK-A-1293-#fJ3" } } ], "must_not": [ { "term": { "postDate": "2017-01-02" } } ] } } } } }
上述查詢是查出
("postDate": "2017-01-01" or "articleID": "XHDK-A-1293-#fJ3") and !("postDate": "2017-01-02")
當需要嵌套是,不能直接bool嵌套,bool是嵌套在should,must,must_not里面的
GET /forum/article/_search { "query": { "constant_score": { "filter": { "bool": { "should": [ { "term": { "postDate": "2017-01-01" } }, { "term": { "articleID": "XHDK-A-1293-#fJ3" } } ], "must": [ { "term": { "postDate": "2017-01-02" } }, { "bool": { "should": [ { "term": { "_id": 3 } } ] } } ] } } } } }