1、查看索引

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

2、新建和删除索引

curl -X PUT 'localhost:9200/myindex?pretty'

创建一个名为 myindex 的索引。pretty要求返回一个漂亮的json 结果

curl -X DELETE 'localhost:9200/myindex?pretty'

删除刚刚创建的索引 myindex

3、索引文档

curl -X PUT "localhost:9200/myindex/_doc/1?pretty" -H 'Content-Type: application/json' -d'{  "website": "www.mybatis.cn"}'

从 myindex 索引中获取指定id的文档

curl -X GET "localhost:9200/myindex/_doc/1?pretty"

4、索引管理

4.1、设置索引的分片和映射

curl -X PUT -H 'Content-Type: application/json' 'localhost:9200/myindex' -d '
{
    "settings": {
        "number_of_shards": 1,
        "number_of_replicas": 1
    },
    "mappings": {
        "properties": {
            "abstract": {
                "type": "text"
            },
            "content": {
                "type": "text"
            },
            "id": {
                "type": "long"
            },
            "keywords": {
                "type": "text"
            },
            "title": {
                "type": "text"
            }
        }
    }
}
'

4.2、修改索引的settings信息

索引的设置信息分为静态信息和动态信息两部分。静态信息不可更改,如索引的主分片数,动态信息可以修改。例如,删除副本分片:

curl -XPUT 'http://localhost:9200/myindex/_settings' -H 'Content-Type: application/json' -d ' 
{
    "index" : {
        "number_of_replicas" : 0
    }
}
'

标签: none

[网站公告]-[2024年兼职介绍]


添加新评论