zoukankan      html  css  js  c++  java
  • Elasticsearch query example

    Serch All:

    GET /_search    //所有索引,所有type下的所有数据都搜索出来
    {
      "query": {
        "match_all": {}
      }
    }
    GET /test_index/_search    //指定一个index,搜索其下所有type的数据
    {
      "query": {
        "match_all": {}
      }
    }
    GET /test_index,test_index2/_search    //同时搜索两个index下的数据
    {
      "query": {
        "match_all": {}
      }
    }
    GET /*1,*2/_search    //按照通配符去匹配多个索引
    {
      "query": {
        "match_all": {}
      }
    }
    GET /test_index/test_type/_search    //搜索一个index下指定的type的数据
    {
      "query": {
        "match_all": {}
      }
    }
    GET /test_index/test_type,test_type2/_search    //可以搜索一个index下多个type的数据
    {
      "query": {
        "match_all": {}
      }
    }
    GET /test_index,test_index2/test_type,test_type2/_search    //搜索多个index下的多个type的数据
    {
      "query": {
        "match_all": {}
      }
    }
    GET /_all/test_type,test_type2/_search    //可以代表搜索所有index下的指定type的数据
    {
      "query": {
        "match_all": {}
      }
    }
    

    Match:

    GET /_search
    {
      "query": {
        "match": {
          "title": "elasticsearch"
        }
      }
    }
    

    multi match:

    GET /_search
    {
      "query": {
        "multi_match": {
          "query": "elasticsearch",
          "fields": ["title","content"]
        }
      }
    }
    

    range query:

    GET /company/employee/_search
    {
      "query": {
        "range": {
          "age": {
            "gte": 30
          }
        }
      }
    }
    

    term query:

    //term 查询被用于精确值 匹配,这些精确值可能是数字、时间、布尔或者那些 not_analyzed 的字符串
    //term 查询对于输入的文本不 分析 ,所以它将给定的值进行精确查询
    GET /_search
    {
      "query": {
        "term": {
          "title":"test hello"
        }
      }
    }
    
    

    terms query:

    //terms 查询和 term 查询一样,但它允许你指定多值进行匹配。
    //如果这个字段包含了指定值中的任何一个值,那么这个文档满足条件:
    { "terms": { "tag": [ "search", "full_text", "nosql" ] }}
    

    定制排序:

    查询的默认情况是按照_score排序的,然而某些情况下,可能没有有用的_score,比如说filter或constant_score

    GET _search
    {
      "query": {
        "bool": {
          "filter": {
            "term": {
              "author_id": 110
            }
          }
        }
      }
    }
    GET _search
    {
      "query": {
        "constant_score": {
          "filter": {
            "term": {
              "author_id": 110
            }
          }
        }
      }
    }
    

      

    定制排序规则

    GET /company/employee/_search
    {
      "query": {
        "constant_score": {
          "filter": {
            "range":{
              "age":{
                "gte":30
              }
            }
          }
        }
      },
      "sort": [
        {
          "join_date": {
            "order": "asc"
          }
        }
      ]
    }
    

      

      

    转自: https://www.jianshu.com/p/5ef2312bf12b  

      

      

      

      

  • 相关阅读:
    JavaScript
    94.Binary Tree Inorder Traversal
    144.Binary Tree Preorder Traversal
    106.Construct Binary Tree from Inorder and Postorder Traversal
    105.Construct Binary Tree from Preorder and Inorder Traversal
    90.Subsets II
    78.Subsets
    83.Merge Sorted Array
    80.Remove Duplicates from Sorted Array II
    79.Word Search
  • 原文地址:https://www.cnblogs.com/allenhaozi/p/8733785.html
Copyright © 2011-2022 走看看