GUI elasticvue
elasticsearch-head https://github.com/mobz/elasticsearch-head
Kaizen https://www.elastic-kaizen.com/
elasticsearch-hq https://github.com/ElasticHQ/elasticsearch-HQ
docker run -p 5000:5000 elastichq/elasticsearch-hq open http://localhost:5000/
djavu https://github.com/appbaseio/dejavu/
1 2 docker run -p 1358:1358 -d appbaseio/dejavu open http://localhost:1358/
参考文档 https://www.ruanyifeng.com/blog/2017/08/elasticsearch.html https://cloud.tencent.com/developer/article/1547867 https://juejin.cn/post/6844903919013855240 https://www.elastic.co/guide/cn/elasticsearch/guide/current/query-dsl-intro.html https://n3xtchen.github.io/n3xtchen/elasticsearch/2017/07/05/elasticsearch-23-useful-query-example https://www.jianshu.com/p/eb30eee13923 https://zhuanlan.zhihu.com/p/34240906 https://feifeiyum.github.io/2020/02/27/es-mapping/ https://cloud.tencent.com/developer/article/1189279
Kibana教程 https://www.ruanyifeng.com/blog/2017/08/elasticsearch.html https://www.jianshu.com/p/7ca9e5b02ef6 https://www.elastic.co/guide/cn/kibana/current/setup.html
查询 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 GET /_cat GET /_cat/indices?v GET /_cat/health?v GET /_mapping?pretty=true PUT /customer?pretty PUT /customer/_doc/1?pretty { "name" : "John Doe" } GET /customer/_doc/1?pretty GET /customer/_search?q=*&sort=name:asc&pretty GET /customer/_mapping?pretty=true GET /customer/_settings?pretty=true GET /bookdb_index/book/_search?q=guide { "query" : { "multi_match" : { "query" : "guide" , "fields" : ["_all" ] } } }
查询2 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 GET /crawl_log/_search/ { "query" : { "match_all" : {} } } GET /bookdb_index/book/_search?q=guide GET /bookdb_index/book/_search { "query" : { "multi_match" : { "query" : "guide" , "fields" : ["_all" ] } } } POST /bookdb_index/book/_search { "query" : { "term" : { "publisher" : "manning" } }, "_source" : ["title" ,"publish_date" ,"publisher" ] } POST /bookdb_index/book/_search { "query" : { "terms" : { "publisher" : ["oreilly" , "packt" ] } } } POST /bookdb_index/book/_search { "query" : { "term" : { "publisher" : "manning" } }, "_source" : ["title" ,"publish_date" ,"publisher" ], "sort" : [ { "publish_date" : {"order" :"desc" }} ] } POST /bookdb_index/book/_search { "query" : { "range" : { "publish_date" : { "gte" : "2015-01-01" , "lte" : "2015-12-31" } } }, "_source" : ["title" ,"publish_date" ,"publisher" ] }
查询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 POST /crawl_log/_search { "query" : { "match_all" : {} } } POST /crawl_log/_search { "query" :{ "term" :{ "task_id" :1 } } } POST /crawl_log/_search { "query" :{ "term" :{ "task_id" :1 }, }, "from" : 10, "size" : 10 } POST /crawl_log/_search { "query" : { "match" : { "message" : "中埃建交五十周年" } } } POST /crawl_log/_search { "query" : { "match_phase" : { "message" : "中埃建交五十周年" } } }
日志查询 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 GET /crawl_log GET /crawl_log/_search POST /crawl_log/_search { "query": { "match_all": {} } } POST /crawl_log/_search { "query": { "bool": { "must": [{ "term": { "task_id": "1" } }, { "match": { "level_name": "INFO" } } ], "must_not": [], "should": [] } }, "from": 0, "size": 10, "sort": [], "aggs": {} }
管理 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 PUT twitte { "settings" : { "number_of_shards" : 3, "number_of_replicas" : 2 } } PUT twitte { "settings" : { "index" : { "number_of_shards" : 3, "number_of_replicas" : 2 } }, "mappings" : { "type1" : { "properties" : { "field1" : { "type" : "text" } } } } } GET /twitte DELETE /twitte
别名 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 GET /_cat/aliases POST /_aliases {"actions" : [{"add" : {"index" : "twitte" , "alias" : "alias1" }}]} POST /_aliases {"actions" : [{"remove" : {"index" : "twitte" , "alias" : "alias1" }}]} POST /_aliases {"actions" : {"add" : {"indices" : ["twitte" , "twitte2" ], "alias" : "alias1" }}} POST /_aliases {"actions" : [{"add" : {"index" : "twitte*" , "alias" : "alias1" }}]}
索引复制 1 2 3 4 5 6 7 8 9 10 11 POST /_reindex?slices=9&refresh&wait_for_completion=false POST _reindex?wait_for_completion=false { "source" : { "index" : "crawl_log" }, "dest" : { "index" : "crawl_log_bak" } }
mapping
字符串: text和keyword
整数 : byte, short, integer, long
浮点数: float, double
布尔型: boolean
日期: date
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 PUT /my-index { "mappings" { "properties" : { "age" : {"type" : "integer" }, "email" : {"type" : "keyword" }, "name" : {"type" : "text" } } } } PUT /my-index/_mapping { "properties" : { "content" : {"type" : "text" } } }
清空数据 1 2 3 4 5 6 7 8 POST /policies_hydrabot/_delete_by_query?refresh&slices=5&pretty { "query" : { "match_all" : {} } }
Curl请求示例 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 curl -X GET 'http://localhost:9200/_cat/indices?v' curl -X GET 'http://localhost:9200/_mapping?pretty=true' curl -X GET 'http://localhost:9200/crawl_log/_mapping?pretty=true' curl -X PUT 'localhost:9200/weather' curl -X DELETE 'localhost:9200/weather' curl -X PUT 'http://localhost:9200/accounts/person/1' \ -H 'Content-Type: application/json' \ -d '{ "user": "张三", "title": "工程师", "desc": "数据库管理" }' curl -X POST 'http://localhost:9200/accounts/person' \ -H 'Content-Type: application/json' \ -d '{ "user": "李四", "title": "工程师", "desc": "系统管理" }' curl 'localhost:9200/accounts/person/1?pretty=true' curl 'localhost:9200/weather/beijing/abc?pretty=true' curl -X DELETE 'localhost:9200/accounts/person/1' curl 'localhost:9200/accounts/person/_search' curl 'localhost:9200/accounts/person/_search' \ -H 'Content-Type: application/json' \ -d ' { "query" : { "match" : { "desc" : "软件" }} }'