bool查询
包含1个或多个查询子句组合,总共包含4个子句,其中2个影响算分QueryContext(must,should),2种不影响算分FilterConext(must_not,filter)。
bool查询中,如果没有must条件,should中必须至少满足一条查询;
bool 查询子查询出现顺序不影响,
数据准备
POST /products/_bulk
{
"index": {
"_id": 1 }}
{
"price" : 10,"avaliable":true,"date":"2018-01-01", "productID" : "XHDK-A-1293-#fJ3" }
{
"index": {
"_id": 2 }}
{
"price" : 20,"avaliable":true,"date":"2019-01-01", "productID" : "KDKE-B-9947-#kL5" }
{
"index": {
"_id": 3 }}
{
"price" : 30,"avaliable":true, "productID" : "JODL-X-1937-#pV7" }
{
"index": {
"_id": 4 }}
{
"price" : 30,"avaliable":false, "productID" : "QQPX-R-3956-#aD8" }
#基本语法
POST /products/_search
{
"query": {
"bool" : {
"must" : {
"term" : {
"price" : "30" }
},
"filter": {
"term" : {
"avaliable" : "true" }
},
"must_not" : {
"range" : {
"price" : {
"lte" : 10 }
}
},
"should" : [
{
"term" : {
"productID.keyword" : "JODL-X-1937-#pV7" } },
{
"term" : {
"productID.keyword" : "XHDK-A-1293-#fJ3" } }
],
"minimum_should_match" :1
}
}
}
#改变数据模型,增加字段。解决数组包含而不是精确匹配的问题
POST /newmovies/_bulk
{
"index": {
"_id": 1 }}
{
"title" : "Father of the Bridge Part II","year":