es配置入门

在这里记录了怎么安装es


1.安装好后,首先要建core,如下:

curl 'http://localhost:9200/test3' -X 'PUT' --data-binary '{"settings":{"index":{"number_of_shards":"5","number_of_replicas":"1"}}}'


2.然后再建mapping文件,用postMan。

5.1是这样,如下图 :


7.8的url改了,是这样:http://localhost:9200/test/_mapping

如果调用多次_mapping,索引的内容会增加而不是替换。

如果字段名一样, 类型不一样,会报错。

增加一个嵌套对象,在kibana里,这样:

PUT /book/_mapping 
{
  "properties":{
    "tweet": { 
      "properties": {
        "tweetKey":            { "type": "text" },
        "user": { 
          "type":             "object",
          "properties": {
            "id":           { "type": "text" },
            "gender":       { "type": "text" },
            "age":          { "type": "long"   },
            "name":   { 
              "type":         "object",
              "properties": {
                "full":     { "type": "text" },
                "first":    { "type": "text" },
                "last":     { "type": "text" }
              }
            }
          }
        }
      }
    }
  }
}


3.增加数据(doc),

注意id就是片键,分片的依据

5.1的:

7.8的:

如果对一个id,重复执行PUT操作,历史记录将被更新,返回如下:

{
  "_index" : "book",
  "_type" : "_doc",
  "_id" : "1",
  "_version" : 5,
  "result" : "updated",
  "_shards" : {
    "total" : 2,
    "successful" : 1,
    "failed" : 0
  },
  "_seq_no" : 7,
  "_primary_term" : 2
}

4.查询数据,用curl

curl 'http://localhost:9200/test/_search' --data-binary '{"query":{"bool":{"must":[{"match_all":{}}],"must_not":[],"should":[]}},"from":0,"size":10,"sort":[],"aggs":{}}'


除了直接http请求还可用kibana来查询:

kibana的安装很简单,从官网下载。解压。

1.vi config/kibana.yml 添加:

elasticsearch.hosts: ["http://127.0.0.1:9200"]

2.进入bin运行./kibana

再进入左边的如下菜单:


查询左边输入命令,右边出结果:


嵌套数据查询:

GET /book/_search?q=tweet.user.id=1

文/程忠 浏览次数:0次   2020-07-21 14:02:39

相关阅读


评论:
点击刷新

↓ 广告开始-头部带绿为生活 ↓
↑ 广告结束-尾部支持多点击 ↑