//查询:query
//1.精确查询:term
$json_term = "{
'term':{
'price':20
}
}";
//用constant_score将term转化为过滤器
$json_term_filter = "{
'query':{
'constant_score':{
'filter':{
'term':{
'price':20
}
}
}
}
}";
//2.组合查询 / 组合过滤器:must必要条件 / should多选一条件 / must_not 必须不要条件
$json_bool = "{
'bool':{
'must':[],
'must_not':[],
'should':[],
}
}";
//将两个term过滤器置于bool过滤器内的should语句内
$json_bool_filter = "{
'query':{
'filtered':{
'filter':{
'bool':{
'should':[
{'term':{'price':20}},
{'term':{'productID':'8745#93-1'}}
],
'must_not':{
'term':{'price':30}
}
}
}
}
}
}";
//嵌套布尔过滤器
$json_bool_filter_2 = '{
"query":{
"filtered":{
"filter":{
"bool":{
"should":[
{"term":{"price":20}},
{"bool":{
"should":[
{"term":{"productID":"9458"}},
{"term":{"price":30}}
]
}}
]
}
}
}
}
}';
//3.多个精确值
$json_terms='{
"query":{
"filtered":{
"filter":{
"terms":{
"price":[20,30]
}
}
}
}
}';
//4.范围 支持时间timestamp / 字母
$json_range = '{
"query":{
"constant_score":{
"filter":{
"range":{
"price":{
"gte":30,
"lt":40
}
}
}
}
}
}';
//范围:加一个月
$json_range_timestamp = '{
"range" : {
"timestamp" : {
"gt" : "2014-01-01 00:00:00",
"lt" : "2014-01-01 00:00:00||+1M"
}
}
}';
//5.匹配查询,返回数据根据字段相关性排序
$json_match = '{
"query":{
"match":{
"title":"quick"
}
}
}';
//匹配查询-多词查询,返回数据根据相关性排序
$json_match_words = '{
"query":{
"match":{
"title":{
"query":"quick dog!",
"operator":"and", //两个词都必须有
"minimum_should_match":"75%", //相关性必须在75%以上
},
}
}
}';
//6.组合查询
$json_bool_match = '{
"query":{
"bool":{
"must":{"match":{"title":"quick"}},
"must_not":{"match":{"title":"lazy"}},
"should":[
{"match":{"title":"brown"}},
{"match":{"title":"dog"}}
]
}
}
}';//不必包含brown / dog,一旦包含,更相关
//控制精确度
$json_bool_should = '{
"query":{
"bool":{
"should":[
{"match":{"title":"brown"}},
{"match":{"title":"quick"}},
{"match":{"title":"dog"}}
],
"minimum_should_match":2 //should中的条件,至少匹配两个
}
}
}';
//7.查询语句超出权重:boost,默认1,提升权重大于1,降低权重0-1,权重是非线性的,计算方法复杂
$json_boost = '{
"query":{
"bool":{
"must":{
"match":{
"content":{
"query":"full text search!",
"operator":"and", //三个词都必须有
},
}
},
"should":[
{
"match":{
"content":{
"query":"elasticsearch",
"boost":3,
},
}
},
{
"match":{
"content":{
"query":"queue",
"boost":2,
},
}
}
]
}
}
}';