Elasticsearch (ES) to create an index

We welcome the attention of the public number: Patricia learn Java , Java push the field of dry goods daily articles, concerned that is free comes with no routine 100G massive study, interviews resources yo! !

Website: https://www.exception.site/elasticsearch/elasticsearch-create-index

First, start to create an index

You can create an index by Elasticsearch of RESTFul API:

PUT http://127.0.0.1:9200/commodity

Note: By default, the number of slices to create the index is 5, the number of copies is one.

You can specify the number of fragments by the following parameters, number of copies:

{
    "settings": {
        "number_of_shards": 3,
        "number_of_replicas": 2
    }
}

1.1 practical demonstration

By CURL command to get started operation about, we try to create a commodity index, look at the effect of:

curl -X PUT "localhost:9200/commodity?pretty"

The index is created successfully returns the following parameters out:

{
  "acknowledged" : true,
  "shards_acknowledged" : true,
  "index" : "commodity"
}

As shown below:

Second, create an index with the type of map (Index)

In fact, when we can create the index, while the index of the type, and the mapping created together:

curl -X PUT "localhost:9200/commodity?pretty"

To the Senate:

{
    "settings": {
        "number_of_shards": 3,
        "number_of_replicas": 2
    },
    "mapping": {
        "_doc": {
            "properties": {
                "commodity_id": {
                    "type": "long"
                },
                "commodity_name": {
                    "type": "text"
                },
                "picture_url": {
                    "type": "keyword"
                },
                "price": {
                    "type": "double"
                }
            }
        }
    }
}

We created a number of slice 3, the copy number of the index 2, while a defined _doctype, which contains four fields, different types.

Next, we create a one-time use with the type of tool Postman index (Index) mapping:

Here should be created for the author CURL index, due into the Senate, there has been a malformed problem, switch to the Postman tools, the same effect.

Third, the number of copies to modify index

We can modify the number of copies of the index by API:

PUT http://127.0.0.1:9200/commodity/_settings

To the Senate:

{
    "number_of_replicas": 3
}

We will commodityindex the number of copies to update 3:

Guess you like

Origin www.cnblogs.com/quanxiaoha2/p/11512623.html