es常用查询
1.{
"sort": [
{
"timeUpdate": {
"order": "desc"
}
}
],
"query": {
"bool": {
"must": [
{
"match": {
"sort": "求助"
}
},
{
"terms": {
"parentType": [
"service",
"community"
]
}
},
{
"match": {
"cityId": 1
}
}
]
}
},
"size": "15"
}
1.查询id
http://192.168.1.85:9200/imembers/comagent/160015a9ec2a4d9731a2014afdd084292a5887
2:更新指定字段
http://192.168.1.85:9200//imembers/comagent/160015a9ec2a4d9731a2014afdd084292a5887/_update
{
"doc": {
"sort400": 0
}
}
3.添加map映射字段
http://192.168.0.60:5601/imembers/_mapping/comagent/ (put)
{
"properties" : {
"sort400" : {
"type" : "integer"
}
}
}
PUT goods_selector_index/_mapping/doc
{
"properties": {
"EventProduct": {
"type": "nested",
"properties": {
"id": {
"type": "integer"
},
"name": {
"type": "keyword",
"ignore_above": 256,
"null_value": ""
},
"title": {
"type": "keyword",
"ignore_above": 256,
"null_value": ""
},
"platform": {
"type": "byte"
},
"state": {
"type": "byte"
}
}
}
}
}
4.聚合排序查法
{
"aggregations": {
"parentId": {
"terms": {
"field": "parentId",
"size": 10000
}
}
},
"sort": [
{
"sort400": {
"order": "asc"
}
},
{
"timeCreate": {
"order": "asc"
}
}
],
"query": {
"bool": {
"must": [
{
"match": {
"state": 20
}
},
{
"terms": {
"cityId": [
1
]
}
}
]
}
}
}
{
"query" : {
"constant_score" : {
"filter" : {
"exists" : { "field" : "tags" }
}
}
}
}
{
"query": {
"bool": {
"must": {
"exists": {
"field": "communityComJson.contractor"
}
},
"must_not": {
"regexp": {
"communityComJson.contractor": ".*+"
}
}
}
},
"_source": [
"communityComJson.contractor"
]
}
{
"query": {
"bool": {
"must": [
{
"exists": {
"field": "communityComJson.contractor"
}
},
{
"regexp": {
"communityComJson.contractor": ".*+"
}
}
]
}
},
"_source": [
"communityComJson.contractor",
"id"
]
}
POST /_aliases
{
"actions": [
{ "remove": { "index": "my_index_v1", "alias": "my_index" }},
{ "add": { "index": "my_index_v2", "alias": "my_index" }}
]
}
http://192.168.1.80:9200/sofangnewcommunity/external/43239/_update/
{
"doc": {
"timeCreateLong": 1513853970000
}
}
//批量操作
POST /library/books/_bulk
{"delete":{"_index":"library","_type":"books","_id":"10"}}
{"create":{"_index":"music","_type":"classic","_id":"1"}}
{"title":"bule music"}
{"index":{"_index":"music","_type":"classic"}}
{"title":"auto generate id"}
{"update":{"_index":"library","_type":"books","_id":"13"}
{ "doc" : {"price":"111"} }
//常用聚合相关例子网址
http://www.cnblogs.com/leeSmall/p/9215909.html
//嵌套nested查询
GET goods_selector_index/doc/_search
{
"query": {
"nested": {
"path": "EventProduct",
"query": {
"bool": {
"must": [
{
"match": {
"EventProduct.id": 1
}
},{
"match": {
"EventProduct.name": "第一个活动"
}
},
{
"match": {
"_id": "d0e7d01c279e38de367773c3333babfd"
}
}
]
}
}
}
},
es修改查询上线设置:5.0以后版本
indices.query.bool.max_clause_count: 10240
//模拟curl请求
curl -XPOST 'http://new-goods-selector-es-search-01:9200/goods_selector_index/doc/_search' -d '{
"query": {
"match_all": {}
},
"_source":["ID","Url"],
"from":0,
"size":1
}'
//es脚本计算max_score得分
{
"query": {
"function_score": {
"query": {
"bool": {
"must": [
{
"match": {
"WebsiteName": "拼多多"
}
}
]
}
},
"script_score": {
"script": {
"lang": "painless",
"inline": "return doc['Price'].value * params.factor",
"params": {
"factor": 2
}
}
}
}
}
}
//es桶聚合嵌套指标聚合并根据聚合数量筛选后再按指标结果排序
POST cps_order_detail_index/doc/_search
{
"query": {
"bool": {
"filter": {
"range": {
"order_time": {
"gte": 1514736000,
"lte": 1546271999
}
}
},
"must": [
{
"term": {
"adv_uid": {
"value": 600233
}
}
},
{
"term": {
"uid": {
"value": 600223
}
}
},
{
"match": {
"goods_name.ansj": "博世"
}
}
],
"must_not": [
{
"match": {
"goods_name.ansj": "西门子"
}
}
],
"should": [
{
"match": {
"goods_name.ansj": "冰箱"
}
}
]
}
},
"aggs": {
"agg_good_id": {
"terms": {
"field": "goods_id",
"size": 10000,
"order": {
"cps": "desc"
}
},
"aggs": {
"gmv": {
"sum": {
"field": "goods_price"
}
},
"cps": {
"sum": {
"field": "commission_real"
}
},
"count_bucket_filter": {
"bucket_selector": {
"buckets_path": {
"cur_doc_cnt": "_count"
},
"script": "params.cur_doc_cnt > 100"
}
}
}
}
},
"size": 0
}