ES常用查询命令
warning:
这篇文章距离上次修改已过192天,其中的内容可能已经有所变动。
Elasticsearch (ES) 是一个基于Lucene的搜索和分析引擎,它可以对大量数据进行即时的复杂查询。以下是一些常见的ES查询命令:
- 查询所有数据:
GET /index_name/_search
- 根据特定查询条件查询数据:
GET /index_name/_search
{
"query": {
"match": {
"field_name": "value"
}
}
}
- 根据ID查询数据:
GET /index_name/_doc/id_value
- 插入数据:
POST /index_name/_doc/
{
"field1": "value1",
"field2": "value2"
}
- 更新数据:
POST /index_name/_update/id_value
{
"doc": {
"field_name": "new_value"
}
}
- 删除数据:
DELETE /index_name/_doc/id_value
- 创建索引:
PUT /index_name
- 删除索引:
DELETE /index_name
- 创建一个索引,并指定设置和映射:
PUT /index_name
{
"settings": {
"number_of_shards": 3,
"number_of_replicas": 2
},
"mappings": {
"properties": {
"field1": {
"type": "text"
},
"field2": {
"type": "keyword"
}
}
}
}
- 使用聚合查询:
GET /index_name/_search
{
"size": 0,
"aggs": {
"group_by_field1": {
"terms": {
"field": "field1.keyword"
}
}
}
}
这些命令可以通过ES的REST API直接执行。每个命令都有其特定的用途和语法,可以根据实际需求进行使用。
评论已关闭