Introduction to Elasticsearch Postman (index creation and addition)

Posted by intermediate on Fri, 03 Jan 2020 22:37:27 +0100

Of course, I don't write about the installation of ES in detail. Baidu has a lot of them. I use 6.2.3 version now.

1. After ES is installed, we start to create indexes and mapping;

 

--PUT http://localhost:9200/local_mst_student_idx_1   

 local_mst_student_idx_1:Represents the index name.

mappings: 

{
    "mappings":{
        "mst_student":{
            "properties":{
                "id":{
                    "type":"long",
                    "fields":{
                        "keyword":{
                            "type":"keyword",
                            "ignore_above":256
                        }
                    }
                },
                "stu_code":{
                    "type":"text",
                    "fields":{
                        "keyword":{
                            "type":"keyword",
                            "ignore_above":256
                        }
                    }
                },
                "stu_name":{
                    "type":"text",
                    "fields":{
                        "keyword":{
                            "type":"keyword",
                            "ignore_above":256
                        }
                    }
                },
                "stu_age":{
                    "type":"integer",
                    "fields":{
                        "keyword":{
                            "type":"keyword",
                            "ignore_above":256
                        }
                    }
                },
                "stu_date":{
                    "type":"long",
                    "fields":{
                        "keyword":{
                            "type":"keyword",
                            "ignore_above":256
                        }
                    }
                },
                "stu_bool":{
                    "type":"boolean",
                    "fields":{
                        "keyword":{
                            "type":"keyword",
                            "ignore_above":256
                        }
                    }
                }
            }
        }
    }
}

After the mapping is created, we can check whether the mapping already exists in ES:

--Get  http://localhost:9200/local_mst_student_idx_2/_mapping?pretty

 

After confirmation, we start to add new operations;

--Post http://127.0.0.1:9200/local_mst_student_idx_2/mst_student/1

body Parameters:

{
    "id":"1",
    "stu_code":"1A0001",
    "stu_name":"Zhang San ",
    "stu_age":"18",
    "stu_date":"1528887157717",
    "stu_bool":"true"
}

How can we view the data we just added after the addition? Next, I will write a query request based on id.

--Post  http://localhost:9200/local_mst_student_idx_2/_search?pretty

bosy Parameters:

{
    "query":{
        "match":{
            "id":"1"
        }
    }
}

 

I'm going to give you a brief introduction to the parameters returned above; in fact, we only focus on the internal parameter values of hits.

took: is the time taken by the query, in milliseconds.

Time out: indicates whether the query times out.

_Shards: describes how many shards are queried, the number of successful shards, and the number of failed Shards.

hits: search results. Total is the total number of satisfied documents. hits is the actual number returned (default is 10).

_Score is the score information of documents, which is related to ranking relevance. It is easy to understand by referring to the search results of major search engines.

total:1; (represents that there is only one piece of data in the current ES. No matter what request you send, ES will return the total)

_Index: we specify the index of the query (similar to a database).

_type: we specify the document to query (similar to a table in the database)

_id: query the specified id.

_source: query return data.

 

Give me a compliment after reading the trouble. I will continue to work hard~

Topics: Java Database