码迷,mamicode.com
首页 > 其他好文 > 详细

ES搜索引擎基本操作

时间:2019-02-07 20:35:53      阅读:233      评论:0      收藏:0      [点我收藏+]

标签:创建   sts   结果   直接   res   max   mic   setting   字段   

一.创建索引库

  执行:技术图片,索引库的名称为zhen

  结果(我已经创建过了,重复执行会报错):

  技术图片

二.创建索引

  1.添加索引

技术图片

  2.添加索引(动态添加新列

技术图片

  3.添加指定id的索引【根据id可以直接修改一前的索引

技术图片

三.搜索

  1.根据id搜索

  技术图片

  2.根据字段搜索【每一个_source对应一条索引

技术图片

  3.多条件组合搜索

[root@zhen ~]# curl -H "Content-Type: application/json" -XGET http://192.168.245.133:9200/zhen/employee/_search?pretty -d ‘
> {
>  "query":
>   {"multi_match":
>    {
>     "query":"bin",
>     "fields":["last_name","first_name"],
>     "operator":"and"
>    }
>   }
> }‘
{
  "took" : 32,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : 3,
    "max_score" : 0.6099695,
    "hits" : [
      {
        "_index" : "zhen",
        "_type" : "employee",
        "_id" : "1",
        "_score" : 0.6099695,
        "_source" : {
          "first_name" : "god bin",
          "last_name" : "pang",
          "age" : 40,
          "about" : "I love to go rock climbing",
          "interests" : [
            "sports",
            "music"
          ]
        }
      },
      {
        "_index" : "zhen",
        "_type" : "employee",
        "_id" : "Nsigx2gBJyzNsh6L2KV0",
        "_score" : 0.2876821,
        "_source" : {
          "first_name" : "bin",
          "age" : 33,
          "about" : "I love to go rock climbing",
          "interests" : [
            "sports",
            "music"
          ]
        }
      },
      {
        "_index" : "zhen",
        "_type" : "employee",
        "_id" : "7cikx2gBJyzNsh6LwqUg",
        "_score" : 0.2876821,
        "_source" : {
          "first_name" : "bin",
          "age" : 33,
          "about" : "I love to go rock climbing",
          "interests" : [
            "sports",
            "music"
          ]
        }
      }
    ]
  }
}

四.修改配置

  执行:curl -H "Content-Type: application/json" -XPUT ‘http://192.168.245.133:9200/zhen/‘ -d‘{"settings":{"number_of_replicas":2}}‘修改副本数 技术图片

  注意:不能在创建索引之后修改配置!

五.查看

技术图片

 

  

ES搜索引擎基本操作

标签:创建   sts   结果   直接   res   max   mic   setting   字段   

原文地址:https://www.cnblogs.com/yszd/p/10355382.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!