赞
踩
总结工作中常用ES脚本,方便日后查阅,此次脚本应用于es5
curl -XPUT 'http://192.168.6.122:9200/major_info'
curl -X PUT --header 'Content-Type: application/json' --header 'Accept: application/json' 'http://127.0.0.1:9200/farer_index' -d@test.json
test.json
- {
- "settings":{
- "number_of_shards":5,
- "number_of_replicas":0
- },
- "mappings":{
- "article":{
- "dynamic":"strict",
- "_all":{
- "enabled":false
- },
- "properties":{
- "title":{
- "type":"string",
- "index":"analyzed",
- "analyzer":"ik_max_word",
- "search_analyzer":"ik_max_word"
- },
- "describe":{
- "type":"string",
- "index":"analyzed",
- "analyzer":"ik_max_word",
- "search_analyzer":"ik_max_word"
- },
- "content":{
- "type":"string",
- "index":"analyzed",
- "analyzer":"ik_max_word",
- "search_analyzer":"ik_max_word"
- },
- "author":{
- "type":"string",
- "index":"no"
- },
- "time":{
- "type":"date",
- "index":"not_analyzed",
- "format":"yyyy-MM-dd HH:mm:ss"
- }
- }
- }
- }
- }
curl -XDELETE 'http://192.168.6.122:9200/major_info_202006'
curl -XPUT '192.168.10.183:9200/test2/entities/_mapping' -d@test.json
mapping文件样例
- {
- "entities" : {
- "dynamic" : "false",
- "properties" : {
- "concept_id" : {
- "type" : "long",
- "store" : true
- },
- "entity_id" : {
- "type" : "long",
- "store" : true
- },
- "entity_name" : {
- "type" : "text",
- "store" : true
- }
- }
- }
- }
curl -XGET '192.168.6.122:9200/weibo_info_202002/_mapping?pretty' > weibo_info_202002.json
curl -XGET 'http://192.168.6.122:9200/_cat/indices?v'
curl '10.128.55.188:9200/_cat/nodes?v'
来源
elasticsearch 查看集群健康、节点状态_u011250186的博客-CSDN博客_es查看集群健康状态
elasticsearch启动后查看是否启动成功:
curl -XGET"http://$(hostname):9200/_cluster/health?pretty=true"2. 停止elasticsearch应用:
curl -XPOST "http:// $(hostname):9200/_shutdown"3. 查看集群健康:
curl $(hostname):9200/_cluster/health?pretty4. 检查集群状态:
curl $(hostname):9200/_cluster/stats?pretty5. 节点状态:
curl $(hostname):9200/_nodes/process?prettycurl $(hostname):9200/_nodes/node1/process?pretty
6. 当你不知道有那些属性可以查看时:
curl '$(hostname):9200/_cat/',会返回可以查看的属性
查看指定索引库的健康状态
http://localhost:9200/_cluster/health/index_name?pretty
http://localhost:9200/_cluster/health/index_name,index_name2?pretty
来源
es 使用curl创建索引模板_laimao8079的博客-CSDN博客_es创建索引模板
curl -X PUT --header 'Content-Type: application/json' --header 'Accept: application/json' 'http://127.0.0.1:9200/_template/people_trail' -d@tmp_people_trail.json
tmp_people_trail.json
- {
- "template":"people_trail*",
- "settings":{
- "index":{
- "number_of_shards":"1",
- "number_of_replicas":"0",
- "analysis":{
- "analyzer":{
- "pinyin":{
- "tokenizer":"pinyin_tokenizer"
- }
- },
- "tokenizer":{
- "pinyin_tokenizer":{
- "type":"pinyin",
- "keep_joined_full_pinyin":true
- }
- }
- }
- }
- },
- "mappings":{
- "_default_":{
- "_all":{
- "enabled":true,
- "analyzer":"standard"
- },
- "dynamic_templates":[
- {
- "xms":{
- "mapping":{
- "fields":{
- "py":{
- "analyzer":"pinyin",
- "type":"text"
- }
- },
- "type":"keyword"
- },
- "match_mapping_type":"string",
- "match":"XM"
- }
- },
- {
- "strings":{
- "match_mapping_type":"string",
- "mapping":{
- "type":"keyword",
- "fields":{
- "full":{
- "type":"text",
- "analyzer":"standard"
- }
- }
- }
- }
- }
- ]
- }
- }
- }
新版本
- {
- "index_patterns": ["my_index*"],
- "aliases": {
- "my_alias": {}
- },
- "settings": {
- "number_of_shards": 1,
- "number_of_replicas": 1
- },
- "mappings": {
- "properties": {
- "field1": {
- "type": "text"
- },
- "field2": {
- "type": "keyword"
- }
- }
- }
- }
旧版本
- {
- "template":"log_info*",
- "mappings":{
- "article":{
- "dynamic":"strict",
- "_all":{
- "enabled":false
- },
- "properties":{
- "title":{
- "type":"string",
- "index":"analyzed",
- "analyzer":"ik_max_word",
- "search_analyzer":"ik_max_word"
- },
- "author":{
- "type":"string",
- "index":"no"
- },
- "itemId":{
- "type":"long"
- },
- "site":{
- "type":"keyword"
- },
- "time":{
- "type":"date",
- "index":"not_analyzed",
- "format":"yyyy-MM-dd HH:mm:ss"
- },
- "laudio":{
- "type":"nested",
- "properties":{
-
- }
- },
- "nfri":{
- "type":"long"
- }
- }
- }
- }
- }
curl -XGET 127.0.0.1:9200/_cat/templates
curl -XGET http://127.0.0.1:9200/_template/article_type?pretty
curl -XDELETE http://127.0.0.1:9200/_template/article_type
- curl -H "Content-Type: application/json" -XPOST 'http://192.168.6.122:9200/_aliases' -d '
- {
- "actions": [
- {"add": {"index": "major_info_202007_v2", "alias": "main_info"}}
- ]
- }'
curl -XGET http://192.168.6.122:9200/major_info_202007/_aliases
curl -XGET '192.168.6.122:9200/_alias/major_info'
- curl -XPOST 'http://192.168.6.122:9200/_aliases' -d '
- {
- "actions" : [
- { "remove" : { "index" : "major_info_202007_v2","alias" : "major_info" } }
- ]
- }'
curl -XGET '192.168.6.122:9200/_alias'
curl -XGET http://192.168.6.122:9200/major_info_202007/major_info_202007/e7af0e55d1307e021f8eb7594bfd3737?pretty
curl -XGET 'http://192.168.6.122:9200/major_info/major_info/_search' -d '{"query":{"match":{"uuid":""}}}'
- curl -XPOST 'localhost:9200/_reindex?pretty' -H 'Content-Type: application/json' -d'
- {
- "source": {
- "index": "twitter"
- },
- "dest": {
- "index": "new_twitter"
- }
- }
- '
curl -XGET 'http://10.128.55.7:6200/news_ref/news_ref/_search' -d '{ "sort" : [{ "pubtime" : {"order" :"desc"}} ],"from":0,"size":10 }'
- curl -XGET 'http://192.168.10.183:9200/info_data/info_data/_search' -d '{"query" : {"term" : { "site_group" : "106" } }, "sort" : [{ "id" : {"order" :"asc"}} ],"from":0,"size":1 }'
-
- curl -XGET 'http://192.168.10.183:9200/info_data/info_data/_search' -d '
- {
- "query":{
- "term":{
- "site_group":"106"
- }
- },
- "sort":[
- {
- "id":{
- "order":"asc"
- }
- }
- ],
- "from":0,
- "size":1
- }
- '
- curl -XGET 'http://192.168.10.183:9200/info_data/info_data/_search' -d '
- {
- "query":{
- "bool":{
- "must":[
- {
- "term":{
- "data_type":"1"
- }
- },
- {
- "term":{
- "site_group":"106"
- }
- }
- ]
- }
- },
- "sort":[
- {
- "id":{
- "order":"asc"
- }
- }
- ],
- "from":0,
- "size":1
- }
- '
这种删除最快,但是一定要慎重,先查询确认,再删除
- curl -X POST "localhost:9200/twitter/_delete_by_query?scroll_size=5000" -H 'Content-Type: application/json' -d'
- {
- "query": {
- "term": {
- "user": "kimchy"
- }
- }
- }
- '
- curl -XGET 'x.x.55.188:9200/second_short_video_info_ref/second_short_video_info_ref/_search' -d'
- {
- "query": {
- "range": {
- "pubtime": {
- "gte": "2022-03-23 00:00:00",
- "lte": "2022-03-23 23:59:00"
- }
- }
- },
- "size":0
- }'
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。