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  

      

      

      

      

  • 相关阅读:
    Celery
    MongoDB-简介
    人工智障
    Flask-session,WTForms,POOL,Websocket通讯原理 -握手,加密解密过程
    web-socket
    flask基础2
    flask的基础1
    项目部署
    nginx简单学习
    redis的安装与配置
  • 原文地址:https://www.cnblogs.com/allenhaozi/p/8733785.html
Copyright © 2011-2022 走看看