zoukankan      html  css  js  c++  java
  • Elasticsearch查询

      有两种基本的方式来运行搜索:一种是在REST请求的URI中发送搜索参数,另一种是将搜索参数发送到REST请求体中。请求体方法的表达能力更好,并且你可以使用更加可读的JSON格式来定义搜索。下面我们用请求体的方式做介绍:

    1、查询全部

     curl -XPOST 'localhost:9200/bank/_search?pretty' -d '
                 {
                   "query": { "match_all": {} }
                 }'

    2、指定查询返回结果个数

    curl -XPOST 'localhost:9200/bank/_search?pretty' -d '
             {
               "query": { "match_all": {} },
               "size": 1
             }'

    3、指定查询返回结果范围

    curl -XPOST 'localhost:9200/bank/_search?pretty' -d '
             {
               "query": { "match_all": {} },
               "from": 10,
               "size": 10
             }'

    4、指定查询返回结果排序规则

    curl -XPOST 'localhost:9200/bank/_search?pretty' -d '
             {
               "query": { "match_all": {} },
               "sort": { "balance": { "order": "desc" } }
             }'

    5、指定查询返回结果字段

    curl -XPOST 'localhost:9200/bank/_search?pretty' -d '
             {
               "query": { "match_all": {} },
               "_source": ["account_number", "balance"]
             }'

    6、指定查询账户编号为20的文档

    curl -XPOST 'localhost:9200/bank/_search?pretty' -d '
             {
               "query": { "match": { "account_number": 20 } }
             }'

    7、指定查询地址中包含“mill”的所有账户

    curl -XPOST 'localhost:9200/bank/_search?pretty' -d '
             {
               "query": { "match": { "address": "mill" } }
             }'

    8、指定查询地址中包含“mill”或者包含“lane”的账户

    curl -XPOST 'localhost:9200/bank/_search?pretty' -d '
             {
               "query": { "match": { "address": "mill lane" } }
             }' 

    9、指定查询地址中包含“mill lane”的账户

    curl -XPOST 'localhost:9200/bank/_search?pretty' -d '
             {
               "query": { "match_phrase": { "address": "mill lane" } }
             }'
  • 相关阅读:
    ES 使用小结
    TruncateATable 清除一张表
    js 排序,去重
    读高性能JavaScript编程 第四章 Conditionals
    读高性能JavaScript编程 第四章 Duff's Device
    c# AOP 文章地址
    String、StringBuffer与StringBuilder之间区别
    批处理命令
    C#中的is和as操作符
    c# 入门
  • 原文地址:https://www.cnblogs.com/hcy-fly/p/7986831.html
Copyright © 2011-2022 走看看