一 常用DSL语句大全
1.1 通过id查询
1.通过id且设置显示的字段查询
{ "_source" : {
"includes" : [
"id",
"title"
],
"excludes" : [ "content"]
},
"query": {
"term": {
"id": "282f85c59020c903e8adff91802815f0"
}
}
}
1.2 时间范围查询
2.通过时间范围查询://注意日期加引号
{
"query": {
"bool": {
"must": [
{
"range": {
"createtime": {
"format": "yyyy-MM-dd HH:mm:ss",
"from": "2017-12-14 16:25:26",
"to": "2017-12-14 17:25:26",
"include_lower": true,
"include_upper": false
}
}
}
]
}
}
}
或者
{
"query": {
"bool": {
"must": [
{
"range": {
"createtime": {
"gt": "2017-12-14 16:25:26",
"lte": "2017-12-14 17:25:26",
"include_lower": true,
"include_upper": false
}
}
}
]
}
}
}
1.3 数字范围查询
3.通过数字区间范围查询
{
"query": {
"bool": {
"must": [
{
"range": {
"similarValue": {
"from": 0.1,
"to": 1,
"include_lower": true,
"include_upper": true
}
}
}
]
}
}
}
1.4 多条件与关系查询
4.通过多条件查询,并且是“与”关系
{
"query": {
"bool": {
"must": [
{
"range": {
"similarValue": {
"from": 0.1,
"to": 1,
"include_lower": true,
"include_upper": true
}
}
},
{
"term": {
"dataSource": "财新网"
}
}
]
}
}
}
1.5 带分页查询
5.带分页的模糊查询
title字段:分词
{
"from": 10,
"size": 20,
"query": {
"match": {
"title": "中国杭州"
}
}
}
contentType:不分词,必须全词条匹配
{
"query": {
"match": {
"contentType": "企业新闻"
}
}
}
1.6 带操作符的模糊查询
6.带操作符的模糊查询,该参数的默认值是"or",变为"and"来要求所有的词条都需要被匹配,提高精确度。
{
"query": {
&