zoukankan      html  css  js  c++  java
  • ElaticSearch基本查询

    刚开始用es查询语法, 感觉很蒙, 什么云里雾里, 网上一大片, 东一篇的西一篇的, 不知所云.  到现在才搞清楚, ES主要是以一种restfulAPI的形式. ES查询方式主要有两种, 但你也可以用_cat命令查看集群情况

    (1)  _cat 的使用

      查看集群的节点信息

    curl -XGET http://192.168.100.3:9200/_cat/nodes?v
    

    查看集群的是否健康

     curl -XGET http://192.168.100.3:9200/_cat/health?v
    

    查看集群的索引情况

    curl -XGET http://192.168.100.3:9200/_cat/indices?v
    

    (2) 通过URI

    ES 的前段可视化工具比较好的有kibbna和head, 这里我选择head作为例子来给大家讲解吧

     curl -XPUT 'localhost:9200/fwcorp/employee/3' -d '{ "first_name" : "Douglas", "last_name" : "Fir", "age" : 35, "about" : "I like to build cabinets", "interests": "forestry" }'
    
     curl -XPUT 'localhost:9200/fwcorp/employee/2' -d '{ "first_name" : "Jane", "last_name" : "Smith", "age" : 32, "about" : "I like to collect rock albums", "interests": "music" }'
    
     curl -XPUT 'localhost:9200/megacorp/employee/1' -d '{ "first_name" : "John", "last_name" : "Smith", "age" : 25, "about" : "I love to go rock climbing", "interests": [ "sports", "music" ] }'
    

      

      

    可以很明显看到有3条数据插入成功了.

    接下来我们通过URI的形式来查询fitst_name 为John的人

    (3)使用Elasticsearch DSL

         其可以通过传递一个JSON请求来获取结果。下面是在所有的字段中搜索带有"John"的结果 .Elaticsearch DSL能满足一些比较复杂的查询,在实际生产中一般选择这种方式. 查询比较灵活

      基本匹配查询(Basic Match Query)

     单字段查询

    curl -XGET '192.168.100.3:9200/fwcorp/employee/_search' -d '
    {
        "query": {
           "match": { "first_name": "John" }
        }
    }'
    

     多字段查询 

    curl -XGET '192.168.100.3:9200/fwcorp/employee/_search' -d '
    {
        "query": {
            "multi_match" : {
                "query" : "John",
                "fields" : ["_all"]
            }
        }
    }'
    

    Boosting
     

  • 相关阅读:
    程序员学习方法差在哪里
    解析域名
    tomcat下的公共jar包配置
    Ubuntu 16.04 修改状态栏位置
    sqlite3 C语言 API 函数
    vim配置文件
    关于 ioctl 函数
    字符设备基础了解
    Ubuntu14.04搭建Boa服务
    gcc 交叉工具链中工具使用(arm-linux-xxx)
  • 原文地址:https://www.cnblogs.com/liqingan/p/10307442.html
Copyright © 2011-2022 走看看