tonglin0325的个人主页

Elasticsearch学习笔记——常用命令

1.创建索引,名字为index

1
2
curl -XPUT http://localhost:9200/index

2.创建一个mapping

1
2
3
4
5
6
7
8
9
10
11
12
curl -XPOST http://localhost:9200/index/fulltext/_mapping -H 'Content-Type:application/json' -d'
{
"properties": {
"content": {
"type": "text",
"analyzer": "ik_max_word",
"search_analyzer": "ik_max_word"
}
}

}'

3.查看mapping

1
2
curl -XPUT http://localhost:9200/xxx/yyy/_mapping

4.删除一个文档,按照id来删除

1
2
curl -XDELETE 'http://localhost:9200/index3/fulltext3/272'

5.通过query来删除文档

不同版本之间的es不太一样,6.2的参考

1
2
https://www.elastic.co/guide/en/elasticsearch/reference/6.2/docs-delete-by-query.html

比如使用kibana里面的dev tool,就可以删掉所有schema字段是“xxxx”的数据

1
2
3
4
5
6
7
8
9
POST xxxxx_2019-12-09/_delete_by_query
{
"query": {
"match": {
"schema": "xxxx"
}
}
}

6.es的task api,参考

1
2
http://xiaorui.cc/archives/3089

7.scroll查看数据,from+size查询最多只能查10000

参考:https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-request-scroll.html

1
2
curl -XPOST -H 'Content-Type: application/json' http://localhost:9200/_search/scroll -d@data.json

data.json

1
2
3
4
{
"scroll" : "1m",
"scroll_id" : "xxxxxxxx"
}

8.删除一个索引

1
2
curl -XDELETE http://ip:port/xxxx