Elasticsearch7 基本命令

分类: JAVA 评论(0) 97 阅读 2021-01-22 16:59 ZooM查看

摘要 Elasticsearch7 基本命令 创建索引、查看节点、查看版本、删除索引等
JAVA

 创建索引 

 Elasticsearch7 在创建索引命令上与之前版本有一些不一样,不能指定索引名称,Elasticsearch6 版本以下命令可以成功创建

curl -H "Content-Type: application/json" -XPUT http://localhost:9200/griffin -d '
{
    "aliases": {},
    "mappings": {
        "accuracy": {
            "properties": {
                "name": {
                    "fields": {
                        "keyword": {
                            "ignore_above": 256,
                            "type": "keyword"
                        }
                    },
                    "type": "text"
                },
                "tmst": {
                    "type": "date"
                }
            }
        }
    },
    "settings": {
        "index": {
            "number_of_replicas": "2",
            "number_of_shards": "5"
        }
    }
}
'

会提示:Root mapping definition has unsupported parameters

原因:ElasticSearch7.X之后的版本默认不在支持指定索引类型,
默认索引类型是_doc(隐含:include_type_name=false),所以在mappings节点后面,直接跟properties就可以了,如下:

curl -H "Content-Type: application/json" -XPUT http://localhost:9200/griffin/accuracy -d '
{
    "aliases": {},
    "mappings": {
        "properties": {
            "name": {
                "fields": {
                    "keyword": {
                        "ignore_above": 256,
                        "type": "keyword"
                    }
                },
                "type": "text"
            },
            "tmst": {
                "type": "date"
            }
        }
    },
    "settings": {
        "index": {
            "number_of_replicas": "2",
            "number_of_shards": "5"
        }
    }
}
'

  查看主节点、节点信息

curl http://localhost:9200/_cat/nodes?pretty

  查看ES版本

curl localhost:9200

  查看指定index

curl http://localhost:9200/index_name/_search?pretty

  查看所有index

curl http://localhost:9200/_cat/indices?v

  删除指定索引index

curl -XDELETE http://localhost:9200/INDEX_NAME

  查看指定数据

curl http://localhost:9200/index_name/_search -d '{"query":{"match":{"itemid":"171206174256759"}}}'

  删除指定数据

curl -XPOST http://localhost:9200/index_name/_delete_by_query -H 'content-Type:application/json' -d '{"query":{"match":{"itemid":"200429182345804"}}}'

后面两个命令未测试过

评论0
评论已关闭