Elasticsearch Postman简单入门(创建索引并新增)

当然ES的安装我就不详细的写了,百度一大堆,本人现在用的是6.2.3 的版本。

1.安装ES后我们开始创建索引和mapping;


Elasticsearch Postman简单入门(创建索引并新增)_第1张图片

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

 local_mst_student_idx_1:代表索引名。

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

                                                                                    }

                                                                            }

                                                                }

                                            }

                                   }

            }

}


mapping创建后我们可以查看一下mapping是否已经在ES中存在:

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


Elasticsearch Postman简单入门(创建索引并新增)_第2张图片

确认完后我们就开始新增操作了;

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

body参数:

{

    "id":"1",

    "stu_code":"1A0001",

    "stu_name":"张三 ",

    "stu_age":"18",

    "stu_date":"1528887157717",

    "stu_bool":"true"

}


Elasticsearch Postman简单入门(创建索引并新增)_第3张图片

新增完成后我们怎么查看到刚才我们新增的数据呢?下面我就写一个根据id查询的请求。

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

bosy参数:

{

    "query": {

        "match":{

                 "id":"1"

        }

    }

}


Elasticsearch Postman简单入门(创建索引并新增)_第4张图片

我就简单给大家讲解一下上面返回的参数;其实我们只关注一下hits内部的参数值就行了。

took:是查询花费的时间,毫秒单位。

time_out:标识查询是否超时。

_shards:描述了查询分片的信息,查询了多少个分片、成功的分片数量、失败的分片数量等。

hits:搜索的结果,total是全部的满足的文档数目,hits是返回的实际数目(默认是10)。

_score是文档的分数信息,与排名相关度有关,参考各大搜索引擎的搜索结果,就容易理解。

total:1;(代表当前ES里总数只有一条数据,不管你发送任何请求,ES都会把总数返回)

_index:我们指定查询的索引(类似数据库的某个库)。

_type:我们指定查询的文档(类似数据库的某张表)

_id:查询指定的id。

_source:查询返回数据。

看完麻烦给个赞吧,我会继续努力的~

你可能感兴趣的:(Elasticsearch Postman简单入门(创建索引并新增))