赞
踩
Elasticsearch结构化搜索 term filter来搜索数据
filter执行原理
搜索发帖日期为2017-01-01,或者帖子ID为XHDK-A-1293-#fJ3的帖子,同时要求帖子的发帖日期绝对不为2017-01-02
GET /post/_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" } } } } } } }
搜索帖子ID为XHDK-A-1293-#fJ3,或者是帖子ID为JODL-X-1937-#pV7而且发帖日期为2017-01-01的帖子
{ "query": { "constant_score": { "filter": { "bool": { "should":[ { "term":{ "articleID" :"XHDK-A-1293-#fJ3" } }, { "bool":{ "must":[ { "term":{ "articleID" :"JODL-X-1937#-#pV7" } }, { "term":{ "postDate" :"2017-01-01" } } ] } } ] } } } } }
should 中匹配任意一个就行,must_not必须不匹配 ,
must 必须匹配
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。