ES操作指南

Creating a text file with the described Elasticsearch operations.

es_operations = """

Elasticsearch 基本操作语法:

  1. 索引文档 (Index Documents):

自动生成 ID:

POST /index_name/_doc

{

"field1": "value1",

"field2": "value2"

}

指定 ID:

PUT /index_name/_doc/1

{

"field1": "value1",

"field2": "value2"

}

  1. 获取文档 (Get Documents):

按 ID 获取:

GET /index_name/_doc/1

  1. 更新文档 (Update Documents):

部分更新文档:

POST /index_name/_update/1

{

"doc": {

"field2": "new_value"

}

}

  1. 删除文档 (Delete Documents):

按 ID 删除:

DELETE /index_name/_doc/1

  1. 查询文档 (Search Documents):

Match 查询:

GET /index_name/_search

{

"query": {

"match": {

"field1": "value"

}

}

}

Term 查询:

GET /index_name/_search

{

"query": {

"term": {

"field1": "exact_value"

}

}

}

Bool 查询:

GET /index_name/_search

{

"query": {

"bool": {

"must": [

{ "match": { "field1": "value" } },

{ "term": { "field2": "exact_value" } }

],

"must_not": [

{ "term": { "field3": "value_to_exclude" } }

],

"should": [

{ "match": { "field4": "optional_value" } }

]

}

}

}

{

"multi_match": {

"query": "search text",

"fields": ["field1", "field2", "field3"]

}

}

  1. 范围查询 (Range Queries):

GET /index_name/_search

{

"query": {

"range": {

"timestamp": {

"gte": "2024-01-01",

"lte": "2024-12-31"

}

}

}

}

  1. 聚合查询 (Aggregations):

按字段分组 (Terms Aggregation):

GET /index_name/_search

{

"size": 0,

"aggs": {

"group_by_field1": {

"terms": {

"field": "field1.keyword"

}

}

}

}

统计 (Stats Aggregation):

GET /index_name/_search

{

"size": 0,

"aggs": {

"field1_stats": {

"stats": {

"field": "field1"

}

}

}

}

  1. 排序 (Sort):

GET /index_name/_search

{

"query": {

"match_all": {}

},

"sort": [

{ "field1": { "order": "asc" } },

{ "field2": { "order": "desc" } }

]

}

  1. 分页 (Pagination):

GET /index_name/_search

{

"query": {

"match_all": {}

},

"from": 0,

"size": 10

}

  1. 批量操作 (Bulk Operations):

POST /_bulk

{ "index": { "_index": "index_name", "_id": "1" } }

{ "field1": "value1" }

{ "delete": { "_index": "index_name", "_id": "2" } }

{ "update": { "_index": "index_name", "_id": "3" } }

{ "doc": { "field2": "new_value" } }

  1. 滚动查询 (Scroll Query):

POST /index_name/_search?scroll=1m

{

"size": 100,

"query": {

"match_all": {}

}

}

使用 _scroll_id 获取后续批次数据:

POST /_search/scroll

{

"scroll": "1m",

"scroll_id":"DXF1ZXJ5QW5kRmV0Y2gBAAAAAAAABbZjaFl1N3dLcmJNTE1GZ1BQOGZqZ3cAAAAAAA"

}

  1. 删除索引 (Delete Index):

DELETE /index_name

相关推荐
SelectDB2 小时前
飞轮科技荣获中国电信星海大数据最佳合作伙伴奖!
大数据·数据库·数据分析
小刘鸭!3 小时前
Hbase的特点、特性
大数据·数据库·hbase
神奇侠20243 小时前
解决集群Elasticsearch 未授权访问漏洞
elasticsearch
Elastic 中国社区官方博客3 小时前
如何通过 Kafka 将数据导入 Elasticsearch
大数据·数据库·分布式·elasticsearch·搜索引擎·kafka·全文检索
神奇侠20243 小时前
解决单台Elasticsearch 未授权访问漏洞
elasticsearch
nece0013 小时前
elasticsearch 杂记
大数据·elasticsearch·搜索引擎
开心最重要(*^▽^*)3 小时前
Es搭建——单节点——Linux
大数据·elasticsearch
学计算机的睿智大学生5 小时前
Hadoop的生态系统所包含的组件
大数据·hadoop·分布式
武子康5 小时前
大数据-259 离线数仓 - Griffin架构 修改配置 pom.xml sparkProperties 编译启动
xml·java·大数据·hive·hadoop·架构
qiquandongkh5 小时前
期权懂|期权新手入门知识:如何挑选期权活跃合约?
大数据·区块链