热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

es示例。。。

{“query”:{“bool”:{“must”:[{“term”:{“type”:2}},{“terms”:{“share_id”:[391,390]}}]}}}{“query



{
“query” : {
“bool” : {
“must” : [
{“term”:{“type”:2}},
{ “terms” : {“share_id” : [391,390]}}
]
}
}
}

{
“query” : {
“bool” : {
“must” : [
{“term”:{“status”:1}},
{“bool”:{“should”:[{ “term” : {“share_id” : 390}},
{ “term” : {“share_id” : 391}}]}}

]
}

}
}
where status =1 and (share_id=390 or share_id=391)

{
“exists” : { “field” : “tags” } tags is not null
“missing” : { “field” : “tags” } tags IS NULL
}



多词匹配
minimum_should_match 百分比
match operator默认or


更高权重
GET /_search
{
“query”: {
“bool”: {
“must”: {这些语句使用默认的 boost 值 1 。
“match”: {
“content”: {
“query”: “full text search”,
“operator”: “and”
}
}
},
“should”: [
{ “match”: {
“content”: {
“query”: “Elasticsearch”,
“boost”: 3 权重配比 这条语句更为重要,因为它有最高的 boost 值。
}
}},
{ “match”: {
“content”: {
“query”: “Lucene”,
“boost”: 2 这条语句比使用默认值的更重要,但它的重要性不及 Elasticsearch 语句。
}
}}
]
}
}
}

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%”
}
}



字段中心式
词中心式 词 peter 和 smith 都必须出现,但是可以出现在任意字段中


{
“query”: {
“multi_match”: {
“query”: “peter smith”,
“type”: “cross_fields”,
“fields”: [ “title^2”, “description” ]
}
}
}title 字段的权重提升值为 2 , description 字段的权重提升值默认为 1

{
“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,
“aggs”: {
“colors”: {–自定义
“terms”: {
“field”: “color”
},
“aggs”: {
“avg_price”: { “avg”: { “field”: “price” }
},
“make” : {–自定义
“terms” : {
“field” : “make”
},
“aggs” : {
“min_price” : { “min”: { “field”: “price”} },
“max_price” : { “max”: { “field”: “price”} }
}
}
}
}
}
}
有四辆红色车。
红色车的平均售价是 $32,500 美元。
其中三辆红色车是 Honda 本田制造,一辆是 BMW 宝马制造。
最便宜的红色本田售价为 $10,000 美元。
最贵的红色本田售价为 $20,000 美元。


{
“size” : 0,
“aggs”: {
“sales”: {
“date_histogram”: {
“field”: “sold”,
“interval”: “month”,
“format”: “yyyy-MM-dd”,
“min_doc_count” : 0,
“extended_bounds” : {
“min” : “2014-01-01”,
“max” : “2014-12-31”
}
}
}
}
}
每月销售多少台汽车

{
“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”
}
},
“aggs”:{
“recent_sales”: {
“filter”: {
“range”: {
“sold”: {
“from”: “now-1M”
}
}
},
“aggs”: {
“average_price”:{
“avg”: {
“field”: “price”
}
}
}
}
}
}
上个月度ford汽车的平均售价。 和 ford汽车所有数据

???{
“size” : 0,
“query”: {
“match”: {
“make”: “ford”
}
},
“post_filter”: {
“term” : {
“color” : “green”
}
},
“aggs” : {
“all_colors”: {
“terms” : { “field” : “color” }
}
}
}查询 部分找到所有的 ford 汽车,然后用 terms 聚合创建一个颜色列表。因为聚合对查询范围进行操作,颜色列表与福特汽车有的颜色相对应。
最后, post_filter 会过滤搜索结果,只展示绿色 ford 汽车。这在查询执行过 后 发生,所以聚合不受影响。






推荐阅读
author-avatar
小林2502927313
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有