跨境互联网 跨境互联网
首页
  • AI 工具

    • 绘图提示词工具 (opens new window)
    • ChatGPT 指令 (opens new window)
  • ChatGPT

    • ChatGP T介绍
    • ChatGPT API 中文开发手册
    • ChatGPT 中文调教指南
    • ChatGPT 开源项目
  • Midjourney

    • Midjourney 文档
  • Stable Diffusion

    • Stable Diffusion 文档
  • 其他

    • AIGC 热门文章
    • 账号合租 (opens new window)
    • 有趣的网站
  • Vue

    • Vue3前置
  • JAVA基础

    • Stream
    • Git
    • Maven
    • 常用第三方类库
    • 性能调优工具
    • UML系统建模
    • 领域驱动设计
    • 敏捷开发
    • Java 测试
    • 代码规范及工具
    • Groovy 编程
  • 并发编程&多线程

    • 并发编程
    • 高性能队列 Disruptor
    • 多线程并发在电商系统下的应用
  • 其他

    • 面试题
  • 消息中间中间件

    • Kafka
    • RabbitMQ
    • RocketMQ
  • 任务调度

    • Quartz
    • XXL-Job
    • Elastic-Job
  • 源码解析

    • Mybatis 高级使用
    • Mybatis 源码剖析
    • Mybatis-Plus
    • Spring Data JPA
    • Spring 高级使用
    • Spring 源码剖析
    • SpringBoot 高级使用
    • SpringBoot 源码剖析
    • Jdk 解析
    • Tomcat 架构设计&源码剖析
    • Tomcat Web应用服务器
    • Zookeeper 高级
    • Netty
  • 微服务框架

    • 分布式原理
    • 分布式集群架构场景化解决方案
    • Dubbo 高级使用
    • Dubbo 核心源码剖析
    • Spring Cloud Gateway
    • Nacos 实战应用
    • Sentinel 实战应用
    • Seata 分布式事务
  • 数据结构和算法的深入应用
  • 存储

    • 图和Neo4j
    • MongoDB
    • TiDB
    • MySQL 优化
    • MySQL 平滑扩容实战
    • MySQL 海量数据存储与优化
    • Elasticsearch
  • 缓存

    • Redis
    • Aerospike
    • Guava Cache
    • Tair
  • 文件存储

    • 阿里云 OSS 云存储
    • FastDF 文件存储
  • 基础

    • Linux 使用
    • Nginx 使用与配置
    • OpenResty 使用
    • LVS+Keepalived 高可用部署
    • Jekins
  • 容器技术

    • Docker
    • K8S
    • K8S
  • 01.全链路(APM)
  • 02.电商终极搜索解决方案
  • 03.电商亿级数据库设计
  • 04.大屏实时计算
  • 05.分库分表的深入实战
  • 06.多维系统下单点登录
  • 07.多服务之间分布式事务
  • 08.业务幂等性技术架构体系
  • 09.高并发下的12306优化
  • 10.每秒100W请求的秒杀架构体系
  • 11.集中化日志管理平台的应用
  • 12.数据中台配置中心
  • 13.每天千万级订单的生成背后痛点及技术突破
  • 14.红包雨的架构设计及源码实现
  • 人工智能

    • Python 笔记
    • Python 工具库
    • 人工智能(AI) 笔记
    • 人工智能(AI) 项目笔记
  • 大数据

    • Flink流处理框架
  • 加密区

    • 机器学习(ML) (opens new window)
    • 深度学习(DL) (opens new window)
    • 自然语言处理(NLP) (opens new window)
AI 导航 (opens new window)

Revin

首页
  • AI 工具

    • 绘图提示词工具 (opens new window)
    • ChatGPT 指令 (opens new window)
  • ChatGPT

    • ChatGP T介绍
    • ChatGPT API 中文开发手册
    • ChatGPT 中文调教指南
    • ChatGPT 开源项目
  • Midjourney

    • Midjourney 文档
  • Stable Diffusion

    • Stable Diffusion 文档
  • 其他

    • AIGC 热门文章
    • 账号合租 (opens new window)
    • 有趣的网站
  • Vue

    • Vue3前置
  • JAVA基础

    • Stream
    • Git
    • Maven
    • 常用第三方类库
    • 性能调优工具
    • UML系统建模
    • 领域驱动设计
    • 敏捷开发
    • Java 测试
    • 代码规范及工具
    • Groovy 编程
  • 并发编程&多线程

    • 并发编程
    • 高性能队列 Disruptor
    • 多线程并发在电商系统下的应用
  • 其他

    • 面试题
  • 消息中间中间件

    • Kafka
    • RabbitMQ
    • RocketMQ
  • 任务调度

    • Quartz
    • XXL-Job
    • Elastic-Job
  • 源码解析

    • Mybatis 高级使用
    • Mybatis 源码剖析
    • Mybatis-Plus
    • Spring Data JPA
    • Spring 高级使用
    • Spring 源码剖析
    • SpringBoot 高级使用
    • SpringBoot 源码剖析
    • Jdk 解析
    • Tomcat 架构设计&源码剖析
    • Tomcat Web应用服务器
    • Zookeeper 高级
    • Netty
  • 微服务框架

    • 分布式原理
    • 分布式集群架构场景化解决方案
    • Dubbo 高级使用
    • Dubbo 核心源码剖析
    • Spring Cloud Gateway
    • Nacos 实战应用
    • Sentinel 实战应用
    • Seata 分布式事务
  • 数据结构和算法的深入应用
  • 存储

    • 图和Neo4j
    • MongoDB
    • TiDB
    • MySQL 优化
    • MySQL 平滑扩容实战
    • MySQL 海量数据存储与优化
    • Elasticsearch
  • 缓存

    • Redis
    • Aerospike
    • Guava Cache
    • Tair
  • 文件存储

    • 阿里云 OSS 云存储
    • FastDF 文件存储
  • 基础

    • Linux 使用
    • Nginx 使用与配置
    • OpenResty 使用
    • LVS+Keepalived 高可用部署
    • Jekins
  • 容器技术

    • Docker
    • K8S
    • K8S
  • 01.全链路(APM)
  • 02.电商终极搜索解决方案
  • 03.电商亿级数据库设计
  • 04.大屏实时计算
  • 05.分库分表的深入实战
  • 06.多维系统下单点登录
  • 07.多服务之间分布式事务
  • 08.业务幂等性技术架构体系
  • 09.高并发下的12306优化
  • 10.每秒100W请求的秒杀架构体系
  • 11.集中化日志管理平台的应用
  • 12.数据中台配置中心
  • 13.每天千万级订单的生成背后痛点及技术突破
  • 14.红包雨的架构设计及源码实现
  • 人工智能

    • Python 笔记
    • Python 工具库
    • 人工智能(AI) 笔记
    • 人工智能(AI) 项目笔记
  • 大数据

    • Flink流处理框架
  • 加密区

    • 机器学习(ML) (opens new window)
    • 深度学习(DL) (opens new window)
    • 自然语言处理(NLP) (opens new window)
AI 导航 (opens new window)
  • MySQL优化

  • MySQL海量数据存储与优化

  • 索引优化注意
  • MySQL平滑扩容实战
  • TiDB

  • 图和Neo4j

  • MongoDB

  • 缓存

  • 文件存储

  • Elasticsearch

    • 1 Elasticsearch基础
    • 2 Elasticsearch入门使用
    • 3 Elasticsearch高级应用
    • 4 Elasticsearch高可用分布式集群
    • 5 Elasticsearch数据模型构建
    • 6 Elasticsearch搜索实战
    • 7 Elasticsearch深度应用及原理
    • 8 Elasticsearch操作总结
      • 精准度搜索
      • 数据建模
      • 索引重建
      • 文件操作
      • 映射高级
      • 智能搜索建议
      • DSL-分页高亮
      • DSL-match_all和full-text
      • Filter-聚合操作
      • tem-level-queries
  • 数据库与缓存
  • Elasticsearch
Revin
2023-07-15
目录

8 Elasticsearch操作总结

# 精准度搜索

DELETE  /article

POST /article/_bulk
{ "create": { "_id": "1"} }
 {"title" : "elasticsearch" }
{ "create": { "_id": "2"} }
{"title" : "java"}
{ "create": { "_id": "3"} }
{"title" : "elasticsearch"}
{ "create": { "_id": "4"} }
{"title" : "hadoop"}
{ "create": { "_id": "5"} }
{"title" : "spark"}

GET /article/_search
{
    "query": {
        "bool": {
            "should": [
                {
                    "term": {
                        "title": {
                            "value": "java"
                        }
                    }
                },
                {
                    "term": {
                        "title": {
                            "value": "spark"
                        }
                    }
                },
                {
                    "term": {
                        "title": {
                            "value": "hadoop"
                        }
                    }
                },
                {
                    "term": {
                        "title": {
                            "value": "elasticsearch"
                        }
                    }
                }
            ]
        }
    }
}

GET /article/_search
{
    "query": {
        "bool": {
            "should": [
                {
                    "term": {
                        "title": {
                            "value": "java",
                            "boost": 5
                        }
                    }
                },
                {
                    "term": {
                        "title": {
                            "value": "spark",
                            "boost": 4
                        }
                    }
                },
                {
                    "term": {
                        "title": {
                            "value": "hadoop",
                            "boost": 3
                        }
                    }
                },
                {
                    "term": {
                        "title": {
                            "value": "elasticsearch"
                        }
                    }
                }
            ]
        }
    }
}

POST /article/_bulk
{ "update": { "_id": "1"} }
{ "doc" : {"content" : "i like to write best elasticsearch article"} }
{ "update": { "_id": "2"} }
{ "doc" : {"content" : "i think java is the best programming language"} }
{ "update": { "_id": "3"} }
{ "doc" : {"content" : "i am only an elasticsearch beginner"} }
{ "update": { "_id": "4"} }
{ "doc" : {"content" : "elasticsearch and hadoop are all very good solution, i am a beginner"} }
{ "update": { "_id": "5"} }
{ "doc" : {"content" : "spark is best big data solution based on scala ,an programming language similar to java"} }

GET /article/_search
{
    "query": {
        "bool": {
            "should": [
                {
                    "match": {
                        "title": "java solution"
                    }
                },
                {
                    "match": {
                        "content": "java solution"
                    }
                }
            ]
        }
    }
}

GET  /article/_search
{
    "query": {
        "dis_max": {
            "queries": [
                {
                    "match": {
                        "title": "java solution"
                    }
                },
                {
                    "match": {
                        "content": "java solution"
                    }
                }
            ]
        }
    }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144

# 数据建模

PUT /user/_doc/1
{
  "name": "John Smith",
  "email": "john@smith.com",
  "dob": "1970/10/24"
}



PUT /blogpost/_doc/2
{
  "title": "Relationships",
  "body": "It's complicated...",
  "user": 1
}

GET /user/_search
{
  "query": {
    "match": {
      "name": "John"
    }
  }
}


GET /blogpost/_search
{
  "query": {
    "terms": {
      "user": [
        1
      ]
    }
  }
}



DELETE /user

DELETE /blogpost

PUT /user/_doc/1
{
  "name": "John Smith",
  "email": "john@smith.com",
  "dob": "1970/10/24"
}



PUT /blogpost/_doc/2
{
  "title": "Relationships",
  "body": "It's complicated...",
  "user": {
    "id": 1,
    "name": "John Smith"
  }
}

GET /blogpost/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "match": {
            "title": "relationships"
          }
        },
        {
          "match": {
            "user.name": "John"
          }
        }
      ]
    }
  }
}


PUT /drivers
{
  "mappings": {
    "properties": {
      "driver": {
        "type": "nested",
        "properties": {
          "last_name": {
            "type": "text"
          },
          "vehicle": {
            "type": "nested",
            "properties": {
              "make": {
                "type": "text"
              },
              "model": {
                "type": "text"
              }
            }
          }
        }
      }
    }
  }
}

PUT /drivers/_doc/1
{
  "driver": {
    "last_name": "McQueen",
    "vehicle": [
      {
        "make": "Powell Motors",
        "model": "Canyonero"
      },
      {
        "make": "Miller-Meteor",
        "model": "Ecto-1"
      }
    ]
  }
}

PUT /drivers/_doc/2?refresh
{
"driver": {
  "last_name": "Hudson",
  "vehicle": [
    {
      "make": "Mifune",
      "model": "Mach Five"
    },
    {
      "make": "Miller-Meteor",
      "model": "Ecto-1"
    }
  ]
}
}

GET /drivers/_search
{
  "query": {
    "nested": {
      "path": "driver",
      "query": {
        "nested": {
          "path": "driver.vehicle",
          "query": {
            "bool": {
              "must": [
                {
                  "match": {
                    "driver.vehicle.make": "Powell  Motors"
                  }
                },
                {
                  "match": {
                    "driver.vehicle.model": "Canyonero"
                  }
                }
              ]
            }
          }
        }
      }
    }
  }
}

PUT my_index
{
  "mappings": {
    "properties": {
      "my_join_field": {
        "type": "join",
        "relations": {
          "question": "answer"
        }
      }
    }
  }
}


PUT /my_index/_doc/1?refresh
{
	"text": "This is a question",
	"my_join_field": {
  	"name": "question"
	}
}

PUT /my_index/_doc/2?refresh
{
	"text": "This is a question2",
	"my_join_field": "question"
}


PUT /my_index/_doc/3?routing=1
{
	"text": "This is an answer",
  "my_join_field": {
    "name": "answer",
    "parent": "1"
  }
}

POST my_index/_search
{
  "query": {
    "has_child": {
      "type": "answer",
      "query" : {
        "match": {
          "text" : "this"
        }
      }
    }
  }
}

GET my_index/_search
{

  "query": {
    "parent_id": {
      "type": "answer",
      "id": "1"
    }
  }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237

# 索引重建

PUT /book/_alias/book_alias

GET /book/_search?scroll=1m

{
"query": {
  "match_all": {}
},
"sort": ["_doc"],
"size": 1
}


GET /_search/scroll
{
  "scroll": "1m",
  "scroll_id" :
  "DXF1ZXJ5QW5kRmV0Y2gBAAAAAAACEgUWQUx2NlhnOGNTTTZLQmpVa3RDank0Zw=="
}


POST _reindex
{
  "source": {
    "index": "book"
  },
  "dest": {
    "index": "book_new"
  }
}

GET /book/_mapping

GET /book_new/_mapping


GET /book_new/_search

{
  "query":{
    "match_all":{}
  }
}


GET /book/_doc/2

GET /book_new/_doc/2

DELETE /book_new

POST _reindex
{
  "source": {
    "index": "book"
  },
  "dest": {
    "index": "book_new",
    "version_type": "external"
  }
}

POST _reindex
{
  "source": {
    "index": "book"
  },
  "dest": {
    "index": "book_new",
    "op_type": "create"
  }
}

POST _reindex
{
  "conflicts": "proceed",
  "source": {
    "index": "book"
  },
  "dest": {
    "index": "book_new",
    "op_type": "create"
  }xw
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84

# 文件操作

POST /lagou-company-index/_doc/1
{
  "name":"百度",
  "job":"小度用户运营经理",
  "payment":"30000",
  "logo":"http://www.lgstatic.com/thubnail_120x120/i/image/M00/21/3E/CgpFT1kVdze  AJNbUAABJB7x9sm8374.png"
}

POST /lagou-company-index/_doc
{
  "name":"百度",
  "job":"算法工程师",
  "payment":"50000",
  "logo":"http://www.lgstatic.com/thubnail_120x120/i/image/M00/21/3E/CgpFT1kVdze AJNbUAABJB7x9sm4464.png"
}

GET /lagou-company-index/_doc/1

POST /lagou-company-index/_search
{
  "query":{
    "match_all":{}
  }
}

POST /lagou-company-index/_doc/_search
{
  "query":{
    "match_all":{}
  }
}

GET /lagou-company-index/_doc/1?_source=name,job

PUT /lagou-company-index/_doc/3
{
"name":"百度",
"job":"AI工程师",
"payment":"60000",
"logo":"http://www.lgstatic.com/thubnail_120x120/i/image/M00/21/3E/CgpFT1kVdzeAJNbUAABJB7x9sm4464.png"
}

GET /lagou-company-index/_doc/3

PUT /lagou-company-index/_doc/3
{
  "job":"AI工程师"
}

POST /lagou-company-index/_update/3
{
  "doc":{
    "job":"AI工程师"
  }
}

DELETE /lagou-company-index/_doc/3

POST /lagou-company-index/_delete_by_query
{
  "query":{
    "match":{
      "name":"百度"
    }
  }
}

PUT /lagou-company-index/_doc/1/_create
{
  "name":"百度",
  "job":"小度用户运营经理",
  "payment":"30000",
  "logo":"http://www.lgstatic.com/thubnail_120x120/i/image/M00/21/3E/CgpFT1kVdzeAJNbUAABJB7x9sm8374.png"
}

GET /lagou-company-index/_doc/1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76

# 映射高级

PUT /company-locations
{
  "mappings": {
    "properties": {
      "name": {
        "type": "text"
      },
      "location": {
        "type": "geo_point"
      }
    }
  }
}

PUT /company-locations/_doc/1
{
  "name":"NetEase",
  "location":"40.715,74.011"
}

PUT /company-locations/_doc/2
{
  "name":"Sina",
  "location":{
    "lat":40.722,
    "lon":73.989
  }
}

PUT /company-locations/_doc/3
{
  "name":"Baidu",
  "location":[73.983,40.719]
}

GET /company-locations/_search
{
  "query": {
    "bool" : {
      "must" : {
        "match_all" : {}
      },
      "filter" : {
        "geo_bounding_box" : {
          "location" : {
            "top_left" : {
              "lat" : 40.73,
              "lon" : 71.12
            },
            "bottom_right" : {
              "lat" : 40.01,
              "lon" : 74.0
            }
          }
        }
      }
    }
  }
}

GET /company-locations/_search
{
  "query": {
    "bool" : {
      "must" : {
        "match_all" : {}
      },
      "filter" : {
        "geo_distance" : {
          "distance" : "350km",
          "location" : {
            "lat" : 40,
            "lon" : 70
          }
        }
      }
    }
  }
}

PUT /user
{
  "settings":{
    "number_of_shards": 3,
    "number_of_replicas": 0
  },
  "mappings":{
    "dynamic": "strict",
    "properties": {
      "name": {"type": "text"},
      "address": {"type": "object", "dynamic": true}
    }
  }
}

PUT /user/_doc/1
{
  "name": "lisi",
  "age": "20",
  "address": {
    "province": "beijing",
    "city": "beijing"
  }
}

DELETE /user

PUT /user
{
  "settings":{
    "number_of_shards": 3,
    "number_of_replicas": 0
  },
  "mappings":{
    "dynamic": true,
    "properties": {
      "name": {"type": "text"},
      "address": {"type": "object", "dynamic": true}
    }
  }
}

PUT /my_index/_doc/1
{
  "note":"2014-01-01"
}

GET /my_index/_mapping

PUT /my_index/_doc/2
{
  "note":"loggout"
}

DELETE /my_index

PUT /my_index
{
  "mappings": {
    "date_detection": false
  }
}

DELETE /my_index

PUT /my_index
{
  "mappings": {
    "dynamic_date_formats": "MM/dd/yyyy"
  }
}

PUT /my_index/_doc/1
{ "note": "2014-01-01" }

PUT /my_index/_doc/1
{ "note": "01/01/2014" }

GET /my_index/_mapping

PUT /my_index2
{
  "mappings": {
    "dynamic_templates": [
      {
        "es": {
          "match": "*_es",
          "match_mapping_type": "string",
          "mapping": {
            "type": "text",
            "analyzer": "spanish"
          }
        }
      },
      {
        "en": {
          "match": "*",
          "match_mapping_type": "string",
          "mapping": {
            "type": "text",
            "analyzer": "english"
          }
        }
      }
    ]
  }
}

GET /my_index2/_mapping

PUT /my_index2/_doc/1
{
  "name_es":"testes",
  "name":"es"
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195

# 智能搜索建议

PUT /blogs/
{
  "mappings": {
    "properties": {
      "body": {
        "type": "text"
      }
    }
  }
}

POST _bulk/?refresh=true
{ "index" : { "_index" : "blogs" } }
{ "body": "Lucene is cool"}
{ "index" : { "_index" : "blogs" } }
{ "body": "Elasticsearch builds on top of lucene"}
{ "index" : { "_index" : "blogs" } }
{ "body": "Elasticsearch rocks"}
{ "index" : { "_index" : "blogs" } }
{ "body": "Elastic is the company behind ELK stack"}
{ "index" : { "_index" : "blogs" } }
{ "body": "elk rocks"}
{ "index" : { "_index" : "blogs"} }
{ "body": "elasticsearch is rock solid"}

POST _analyze
{
  "text": [
    "Lucene is cool",
    "Elasticsearch builds on top of lucene",
    "Elasticsearch rocks",
    "Elastic is the company behind ELK stack",
    "elk rocks",
    "elasticsearch is rock solid"
  ]
}

POST /blogs/_search
{
  "suggest": {
    "my-suggestion": {
      "text": "lucne rock",
      "term": {
        "suggest_mode": "missing",
        "field": "body"
      }
    }
  }
}

POST /blogs/_search
{
  "suggest": {
    "my-suggestion": {
      "text": "lucne rocks",
      "term": {
        "suggest_mode": "popular",
        "field": "body"
      }
    }
  }
}

POST /blogs/_search
{
  "suggest": {
    "my-suggestion": {
      "text": "lucne rocks",
      "term": {
        "suggest_mode": "always",
        "field": "body"
      }
    }
  }
}

POST /blogs/_search
{
  "suggest": {
    "my-suggestion": {
      "text": "lucne and elasticsear rock",
      "phrase": {
        "field": "body",
        "highlight": {
          "pre_tag": "<em>",
          "post_tag": "</em>"
        }
      }
    }
  }
}

PUT /blogs_completion/
{
  "mappings": {
    "properties": {
      "body": {
        "type": "completion"
      }
    }
  }
}

POST _bulk/?refresh=true
{ "index" : { "_index" : "blogs_completion" } }
{ "body": "Lucene is cool"}
{ "index" : { "_index" : "blogs_completion" } }
{ "body": "Elasticsearch builds on top of lucene"}
{ "index" : { "_index" : "blogs_completion"} }
{ "body": "Elasticsearch rocks"}
{ "index" : { "_index" : "blogs_completion" } }
{ "body": "Elastic is the company behind ELK stack"}
{ "index" : { "_index" : "blogs_completion" } }
{ "body": "the elk stack rocks"}
{ "index" : { "_index" : "blogs_completion"} }
{ "body": "elasticsearch is rock solid"}

POST /blogs_completion/_search?pretty
{ 
"size": 0,
"suggest": {
  "blog-suggest": {
    "prefix": "elastic i",
    "completion": {
      "field": "body"
    }
  }
}
}

DELETE /blogs_completion

PUT /blogs_completion/
{
  "mappings": {
    "properties": {
      "body": {
        "type": "completion",
        "analyzer":"english"
      }
    }
  }
}

POST _bulk/?refresh=true
{ "index" : { "_index" : "blogs_completion" } }
{ "body": "Lucene is cool"}
{ "index" : { "_index" : "blogs_completion" } }
{ "body": "Elasticsearch builds on top of lucene"}
{ "index" : { "_index" : "blogs_completion"} }
{ "body": "Elasticsearch rocks"}
{ "index" : { "_index" : "blogs_completion" } }
{ "body": "Elastic is the company behind ELK stack"}
{ "index" : { "_index" : "blogs_completion" } }
{ "body": "the elk stack rocks"}
{ "index" : { "_index" : "blogs_completion"} }
{ "body": "elasticsearch is rock solid"}

POST /blogs_completion/_search?pretty
{
    "size": 0,
    "suggest": {
        "blog-suggest": {
            "prefix": "elastic i",
            "completion": {
                "field": "body"
            }
        }
    }
}


POST _analyze
{
  "text": "elasticsearch is rock solid",
  "analyzer":"english"
}

POST _analyze
{
  "text": "elasticsearch is rock solid"
}

POST /blogs_completion/_search?pretty
{
    "size": 0,
    "suggest": {
        "blog-suggest": {
            "prefix": "elastic is",
            "completion": {
                "field": "body"
            }
        }
    }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195

# DSL-分页高亮

GET /book/_search
{
  "query": {
    "term" : { "description" : "solr"}
  }
}

GET /book/_search
{
  "query": {
    "constant_score" : {
      "filter" : {
        "term" : { "description" : "solr"}
      },
      "boost" : 1.2
    }
  }
}

POST /book/_search
{
  "query": {
    "bool" : {
      "should" : {
        "match" : { "description" : "java" }
      },
      "filter": {
        "term" : { "name" : "solr" }
      },
      "must_not" : {
        "range" : {
          "price" : { "gte" : 200, "lte" : 300 }
        }
      },
      "minimum_should_match" : 1,
      "boost" : 1.0
    }
  }
}

POST /book/_search
{
  "query": {
    "match": {"description":"solr"}
  }
}

POST /book/_search
{
  "query": {
    "match": {"description":"solr"}
  },
  "sort": [
    {"_score": {"order": "asc"}}
  ]
}

POST /book/_search
{
  "query": {
    "match_all": {}
  },
  "sort": [
    {"price": {"order": "desc"}}
  ]
}

POST /book/_search
{
  "query":{
    "match_all":{}
  },
  "sort": [
    { "price": { "order": "desc" }},
    { "timestamp": { "order": "desc" }}
  ]
}

POST /book/_search
{
  "query": {
    "match_all": {}
  },
  "sort": [
    {"price": {"order": "desc"}}
  ],
  "size": 2,
  "from": 0
}

POST /book/_search
{
  "query": {
    "match_all": {}
  },
  "sort": [
    {"price": {"order": "desc"}}
  ],
  "size": 2,
  "from": 2
}

POST /book/_search
{
  "query": {
    "match": {
      "name": "elasticsearch"
    }
  },
  "highlight": {
    "pre_tags": "<font color='pink'>",
    "post_tags": "</font>",
    "fields": [{"name":{}}]
  }
}

POST /book/_search
{
  "query": {
    "match": {
      "name": "elasticsearch"
    }
  },
  "highlight": {
    "pre_tags": "<font color='pink'>",
    "post_tags": "</font>",
    "fields": [{"name":{}},{"description":{}}]
  }
}

POST /book/_search
{
  "query": {
    "query_string" : {
      "query" : "elasticsearch"
    }
  },
  "highlight": {
    "pre_tags": "<font color='pink'>",
    "post_tags": "</font>",
    "fields": [{"name":{}},{"description":{}}]
  }
}

GET /_mget
{
  "docs" : [
    {
      "_index" : "book",
      "_id" : 2
    },
    {
      "_index" : "lagou-company-index",
      "_id" : 1
    }
  ]
}

GET /book/_mget
{
  "docs" : [
    {
      "_id" : 2
    },
    {
      "_id" : 3
    }
  ]
}

POST /_bulk
{ "delete": { "_index": "book", "_id": "1" }}
{ "create": { "_index": "book", "_id": "5" }}
{ "name": "test14","price":100.99 }
{ "update": { "_index": "book", "_id": "2"} }
{ "doc" : {"name" : "test"} }
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176

# DSL-match_all和full-text

POST /lagou-company-index/_search
{
  "query":{
    "match_all":{}
  }
}

POST /company-locations/_search
{
  "query":{
    "match_all":{}
  }
}

PUT /lagou-property
{
  "settings": {},
  "mappings": {
    "properties": {
      "title": {
        "type": "text",
        "analyzer": "ik_max_word"
      },
      "images": {
        "type": "keyword"
      },
      "price": {
        "type": "float"
      }
    }
  }
}

POST /lagou-property/_doc/
{
  "title": "小米电视4A",
  "images": "http://image.lagou.com/12479122.jpg",
  "price": 4288
}

POST /lagou-property/_doc/
{
  "title": "小米手机",
  "images": "http://image.lagou.com/12479622.jpg",
  "price": 2699
}

POST /lagou-property/_doc/
{
  "title": "华为手机",
  "images": "http://image.lagou.com/12479922.jpg",
  "price": 5699
}

POST /lagou-property/_search
{
  "query":{
    "match":{
      "title":"小米电视4A"
    }
  }
}

POST /lagou-property/_search
{
  "query": {
    "match": {
      "title": {
        "query": "小米电视4A",
        "operator": "and"
      }
    }
  }
}

GET /lagou-property/_search
{
  "query": {
    "match_phrase": {
      "title": "小米电视"
    }
  }
}

GET /lagou-property/_search
{
  "query": {
    "match_phrase": {
      "title": "小米 4A"
    }
  }
}

GET /lagou-property/_search
{
  "query": {
    "match_phrase": {
      "title": {
        "query": "小米 4A",
        "slop": 3
      }
    }
  }
}

GET /lagou-property/_search
{
  "query": {
    "query_string" : {
      "query" : "2699"
    }
  }
}

GET /lagou-property/_search
{
  "query": {
    "query_string" : {
      "query" : "2699",
      "default_field" : "title"
    }
  }
}

GET /lagou-property/_search
{
  "query": {
    "query_string" : {
      "query" : "手机 OR 小米",
      "default_field" : "title"
    }
  }
}

GET /lagou-property/_search
{
  "query": {
    "query_string" : {
      "query" : "手机 AND 小米",
      "default_field" : "title"
    }
  }
}

GET /lagou-property/_search
{
  "query": {
    "query_string" : {
      "query" : "大米~1",
      "default_field" : "title"
    }
  }
}

GET /lagou-property/_search
{
  "query": {
    "query_string" : {
      "query":"2699",
      "fields": [ "title","price"]
    }
  }
}

POST /lagou-property/_search
{
  "query": {
    "multi_match" : {
      "query":"2699",
      "fields": [ "title","price"]
    }
  }
}

POST /lagou-property/_search
{
  "query": {
    "multi_match" : {
      "query":"2699",
      "fields": [ "title","pr*"]
    }
  }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183

# Filter-聚合操作

POST /book/_search
{
  "query": {
    "filtered": {
      "query": {
        "match_all": {}
      },
      "filter": {
        "range": {
          "price": {
            "gte": 200,
            "lte": 1000
          }
        }
      }
    }
  }
}

POST /book/_search
{
  "query": {
    "bool": {
      "must": {
        "match_all": {}
      },
      "filter": {
        "range": {
          "price": {
            "gte": 200,
            "lte": 1000
          }
        }
      }
    }
  }
}

GET /book/_search?explain
{
"query": {
  "match1": {
    "name": "test"
  }
}
}

GET /book/_validate/query?explain
{
"query": {
  "match1": {
    "name": "test"
  }
}
}

POST /book/_search
{
  "size": 0,
  "aggs": {
    "max_price": {
      "max": {
        "field": "price"
      }
    }
  }
}

POST /book/_count
{
  "query": {
    "range": {
      "price" : {
        "gt":100
      }
    }
  }
}

POST /book/_search?size=0
{
"aggs": {
  "price_count": {
    "value_count": {
      "field": "price"
    }
  }
}
}

POST /book/_search?size=0
{
"aggs": {
  "_id_count": {
    "cardinality": {
      "field": "_id"
    }
  },
  "price_count": {
    "cardinality": {
      "field": "price"
    }
  }
}
}

POST /book/_search?size=0
{
"aggs": {
  "price_stats": {
    "stats": {
      "field": "price"
    }
  }
}
}

POST /book/_search?size=0
{
"aggs": {
  "price_stats": {
    "extended_stats": {
      "field": "price"
    }
  }
}
}

POST /book/_search?size=0
{
"aggs": {
  "price_percents": {
    "percentiles": {
      "field": "price"
    }
  }
}
}

POST /book/_search?size=0
{
"aggs": {
  "price_percents": {
    "percentiles": {
      "field": "price",
      "percents" : [75, 99, 99.9]
    }
  }
}
}

POST /book/_search?size=0
{
"aggs": {
  "gge_perc_rank": {
    "percentile_ranks": {
      "field": "price",
      "values": [
        100,200
      ]
    }
  }
}
}

POST /book/_search
{
  "size": 0,
  "aggs": {
    "group_by_price": {
      "range": {
        "field": "price",
        "ranges": [
          {
            "from": 0,
            "to": 200
          },
          {
            "from": 200,
            "to": 400
          },
          {
            "from": 400,
            "to": 1000
          }
        ]
      },
      "aggs": {
        "average_price": {
          "avg": {
            "field": "price"
          }
        }
      }
    }
  }
}

POST /book/_search
{
  "size": 0,
  "aggs": {
    "group_by_price": {
      "range": {
        "field": "price",
        "ranges": [
          {
            "from": 0,
            "to": 200
          },
          {
            "from": 200,
            "to": 400
          },
          {
            "from": 400,
            "to": 1000
          }
        ]
      },
      "aggs": {
        "average_price": {
          "avg": {
            "field": "price"
          }
        },
        "count_price": {
          "value_count": {
            "field": "price"
          }
        }
      }
    }
  }
}

POST /book/_search
{
  "size": 0,
  "aggs": {
    "group_by_price": {
      "range": {
        "field": "price",
        "ranges": [
          {
            "from": 0,
            "to": 200
          },
          {
            "from": 200,
            "to": 400
          },
          {
            "from": 400,
            "to": 1000
          }
        ]
      },
      "aggs": {
        "average_price": {
          "avg": {
            "field": "price"
          }
        },
        "having": {
          "bucket_selector": {
            "buckets_path": {
              "avg_price": "average_price"
            },
            "script": {
              "source": "params.avg_price >= 200 "
            }
          }
        }
      }
    }
  }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278

# tem-level-queries

PUT /book
{
  "settings": {},
  "mappings" : {
    "properties" : {
      "description" : {
        "type" : "text",
        "analyzer" : "ik_max_word"
      },
      "name" : {
        "type" : "text",
        "analyzer" : "ik_max_word"
      },
      "price" : {
        "type" : "float"
      },
      "timestamp" : {
        "type" : "date",
        "format" : "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis"
      }
    }
  }
}

PUT /book/_doc/1
{
  "name": "lucene",
  "description": "Lucene Core is a Java library providing powerful indexing and search features, as well as spellchecking, hit highlighting and advanced analysis/tokenization capabilities. The PyLucene sub project provides Python bindings for Lucene Core. ",
  "price":100.45,
  "timestamp":"2020-08-21 19:11:35"
}

PUT /book/_doc/2
{
  "name": "solr",
  "description": "Solr is highly scalable, providing fully fault tolerant distributed indexing, search and analytics. It exposes Lucenes features through easy to use JSON/HTTP interfaces or native clients for Java and other languages.",
  "price":320.45,
  "timestamp":"2020-07-21 17:11:35"
}

PUT /book/_doc/3
{
  "name": "Hadoop",
  "description": "The Apache Hadoop software library is a framework that allows for the distributed processing of large data sets across clusters of computers using simple programming models.",
  "price":620.45,
  "timestamp":"2020-08-22 19:18:35"
}

PUT /book/_doc/4
{
  "name": "ElasticSearch",
  "description": "Elasticsearch是一个基于Lucene的搜索服务器。它提供了一个分布式多用户能力的全文搜索引擎,基于RESTful web接口。Elasticsearch是用Java语言开发的,并作为Apache许可条款下的开放源码发布,是一种流行的企业级搜索引擎。Elasticsearch用于云计算中,能够达到实时搜索,稳定,可靠,快速,安装使用方便。官方客户端在Java、.NET(C#)、PHP、Python、Apache Groovy、Ruby和许多其他语言中都是可用的。根据DB-Engines的排名显示,Elasticsearch是最受欢迎的企业搜索引擎,其次是Apache Solr,也是基于Lucene。",
  "price":999.99,
  "timestamp":"2020-08-15 10:11:35"
}

POST /book/_search
{
  "query":{
    "term":{
      "name":"solr"
    }
  }
}

POST /book/_search
{
  "query":{
    "terms":{
      "name":["solr","elasticsearch"]
    }
  }
}

GET /book/_search
{
  "query": {
    "range" : {
      "price" : {
        "gte" : 10,
        "lte" : 200,
        "boost" : 2.0
      }
    }
  }
}

GET /book/_search
{
  "query": {
    "range" : {
      "timestamp" : {
        "gte" : "now-7d/d",
        "lt" : "now/d"
      }
    }
  }
}

GET book/_search
{
  "query": {
    "range" : {
      "timestamp" : {
        "gte": "18/06/2020",
        "lte": "2021",
        "format": "dd/MM/yyyy||yyyy"
      }
    }
  }
}

GET /book/_search
{
  "query": {
    "exists" : { "field" : "price" }
  }
}

POST /book/_search
{
  "query":{
    "prefix":{
      "name":"so"
    }
  }
}

GET /book/_search
{
  "query": {
    "wildcard" : { "name" : "So*r" }
  }
}

GET /book/_search
{
  "query": {
    "wildcard": {
      "name": {
        "value": "lu*",
        "boost": 2
      }
    }
  }
}

GET /book/_search
{
  "query": {
    "regexp":{
      "name": "s.*"
    }
  }
}

GET /book/_search
{
  "query": {
    "regexp":{
      "name": {
        "value":"s.*",
        "boost":1.2
      }
    }
  }
}

GET /book/_search
{
  "query": {
    "fuzzy" : { "name" : "so" }
  }
}

GET /book/_search
{
  "query": {
    "fuzzy" : {
      "name" : {
        "value": "so",
        "boost": 1.0,
        "fuzziness": 2
      }
    }
  }
}

GET /book/_search
{
  "query": {
    "fuzzy" : {
      "name" : {
        "value": "sorl",
        "boost": 1.0,
        "fuzziness": 2
      }
    }
  }
}

GET /book/_search
{
  "query": {
    "ids" : {
      "values" : ["1", "3"]
    }
  }
}

POST /book/_search
{
  "query":{
    "terms":{
      "_id":[1,3]
    }
  }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
上次更新: 2025/04/03, 11:07:08
7 Elasticsearch深度应用及原理

← 7 Elasticsearch深度应用及原理

最近更新
01
tailwindcss
03-26
02
PaddleSpeech
02-18
03
whisper
02-18
更多文章>
Theme by Vdoing | Copyright © 2019-2025 跨境互联网 | 豫ICP备14016603号-5 | 豫公网安备41090002410995号
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式