{
“query” : {
“bool” : {
“must” : [
{“term”:{“status”:1}},
{“bool”:{“should”:[{ “term” : {“share_id” : 390}},
{ “term” : {“share_id” : 391}}]}}
]
}
{
“exists” : { “field” : “tags” } tags is not null
“missing” : { “field” : “tags” } tags IS NULL
}
dis_max (Disjunction Max Query)将任何与任一查询匹配的文档作为结果返回,
但只将最佳匹配的评分作为查询的评分结果返回
{
“query”: {
“dis_max”: {
“queries”: [
{ “match”: { “title”: “Brown fox” }},
{ “match”: { “body”: “Brown fox” }}
]
}
}
}
{
“query”: {
“dis_max”: {
“queries”: [
{ “match”: { “title”: “Quick pets” }},
{ “match”: { “body”: “Quick pets” }}
],
“tie_breaker”: 0.3 参数将其他匹配语句的评分也考虑其中
}
}
}===》{
“multi_match”: {
“query”: “Quick brown fox”,
“type”: “best_fields”, best_fields 、 most_fields 和 cross_fields (最佳字段(默认)、多数字段、跨字段)。
“fields”: [ “title”, “body” ],
“tie_breaker”: 0.3,
“minimum_should_match”: “30%”
}
}
{
“query” :{
“term”:{“city_id”:1001}
},
"size" : 0,
"aggs" : {
"popular_colors" : {
"terms" : {
"field" : "building_id"
},
"aggs": {
"avg_price": {
"avg": {
"field": "unit_price"
}
}
}
}
}
}==聚合 select avg(unit_price) where city_id=1001 group by building_id;
{
“size” : 0,
“query” : {
“match” : {
“make” : "ford"聚合操作在查询范围内(例如:所有文档匹配 ford )
}
},
“aggs” : {
“single_avg_price”: {
“avg” : { “field” : “price” }
},
“all”: {
“global” : {}, global 全局桶没有参数。
“aggs” : {
“avg_price”: {
“avg” : { “field” : “price” }
}
}
}
}
???{
“size” : 0,
“query”: {
“match”: {
“make”: “ford”
}
},
“post_filter”: {
“term” : {
“color” : “green”
}
},
“aggs” : {
“all_colors”: {
“terms” : { “field” : “color” }
}
}
}查询 部分找到所有的 ford 汽车,然后用 terms 聚合创建一个颜色列表。因为聚合对查询范围进行操作,颜色列表与福特汽车有的颜色相对应。
最后, post_filter 会过滤搜索结果,只展示绿色 ford 汽车。这在查询执行过 后 发生,所以聚合不受影响。