ES搜索常用查询

1、mapping获取

GET book/_mapping

2、match_all——查询所有

GET book/_search
{
  "query":{
    "match_all": {}
  }
}

3、查询数据的范围

GET book/_search
{
  "from":0,
  "size": 10
}

4、排序

GET book/_search
{
  "sort": [
    {
      "created_date": {"order": "desc"}
	}
  ]
}

5、返回总数量

GET book/_search
{
	"track_total_hits": 2147483647
}

6、返回指定列,剔除指定列

GET book/_search
{
	"_source": {
		"includes": [
			"id"
		],
		"excludes": ["time"]
	}
}

7、筛选数据
terms 等同于mysql的in
term 等同于mysql的=
下面的示例:查询id in(“2a7e6e7aee4948829ee302c0eb6f882a”,“d4d03625a912414eb33617e9603db7e1”)and product =‘NetWork,Storage’

GET book/_search
{
	"from": 0,
	"size": 10,
	"query": {
		"bool": {
			"filter": [		
				"term": {
					"product": {
						"value": "NetWork,Storage",
						"boost": 1.0
					}
				},
			"terms": {
				"id": [
					"2a7e6e7aee4948829ee302c0eb6f882a",
					"d4d03625a912414eb33617e9603db7e1"
				],
				"boost": 1.0
			}
		]
	}
	"_source": {
		"includes": [
			"id"
		],
		"excludes": []
	},
	"track_total_hits": 2147483647
}

8、模糊搜索
9、or
10、sum
GET betam_hc_self_cbccrmasstsalesservicedb.v_report_account_v2_gray/_search
{

"query": {
	"bool": {
		"filter": [
		  {
				"terms": {
					"t_account_cdhnumber": [
						 "102208020","1003391365"
						],
						"boost": 1.0
					}
				}
		],
		"adjust_pure_negative": true,
		"boost": 1.0
	}
},
"aggs": {
  "sum_number": {
    "sum": {
      "field": "t_account_operational_excellence"
    }
  },
  "sum_number2": {
    "sum": {
      "field": "t_account_legalflagcode"
    }
  }
}

}

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值