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

    查询API

    GET /twitter/_search?q=user:kimchy
    GET /twitter/tweet,user/_search?q=user:kimchy
    GET /kimchy,elasticsearch/tweet/_search?q=tag:wow
    GET /_all/tweet/_search?q=tag:wow
    GET /_search?q=tag:wow
    
    GET twitter/tweet/_search?q=user:kimchy
    

    q

    The query string (maps to the query_string query, see Query String Query for more details).

    请求主体查询

    GET /twitter/tweet/_search
    {
        "explain": true,
        "version": true,
        "query" : {
            "term" : { "user" : "kimchy" }
        },
        "from" : 0,
        "size" : 10,
        "sort" : [
            { "post_date" : {"order" : "asc"}},
            "user",
            { "name" : "desc" },
            { "age" : "desc" },
            "_score"
        ],
        "_source": [ "obj1.*", "obj2.*" ],
        "script_fields" : {
            "test1" : {
                "script" : "params['_source']['message']"
            }
        },
        "post_filter": { 
            "term": { "color": "red" }
        },
        "highlight" : {
            "pre_tags" : ["<tag1>", "<tag2>"],
            "post_tags" : ["</tag1>", "</tag2>"],
            "fields" : {
                "_all" : {}
            }
        }
    }
    

    Inner hits

    Query DSL

    全文搜索(Full text queries)

    match

    标准全文查询

    GET /_search
    {
        "query": {
            "match" : {
                "message" : "this is a test"
            }
        }
    }
    
    match_phrase

    短语查询,支持分词

    GET /_search
        {
            "query": {
                "match_phrase" : {
                    "message" : {
                        "query" : "this is a test",
                        "analyzer" : "my_analyzer"
                    }
                }
            }
        }
    
    match_phrase_prefix
    GET /_search
    {
        "query": {
            "match_phrase_prefix" : {
                "message" : {
                    "query" : "quick brown f",
                    "max_expansions" : 10
                }
            }
        }
    }
    
    multi_match

    支持多字段版本

    GET /_search
    {
      "query": {
        "multi_match" : {
          "query" : "this is a test",
          "fields" : [ "subject^3", "message" ] 
        }
      }
    }
    
    common_terms

    停止符(stopwords)

    GET /_search
    {
        "query": {
            "common": {
                "body": {
                    "query": "this is bonsai cool",
                        "cutoff_frequency": 0.001
                }
            }
        }
    }
    
    query_string

    查询解析

    GET /_search
    {
        "query": {
            "query_string" : {
                "default_field" : "content",
                "query" : "this AND that OR thus"
            }
        }
    }
    
    simple_query_string

    使用 SimpleQueryParser去解析查询语句

    GET /_search
    {
      "query": {
        "simple_query_string" : {
            "query": ""fried eggs" +(eggplant | potato) -frittata",
            "analyzer": "snowball",
            "fields": ["body^5","_all"],
            "default_operator": "and"
        }
      }
    }
    

    Term级别查询

    更底层的查询

    • Term

    • Terms

    • range

    • exists

    • prefix

    • wildcard

    • regexp

    • fuzzy

    • type

    • ids

      GET /_search
      {
      "query": {
      "constant_score" : {
      "filter" : {
      "terms" : { "user" : ["kimchy", "elasticsearch"]}
      }
      }
      }
      }

    组合查询(Compound queries)

    • constant_score

    • bool

    • dis_max

    • function_score

    • boosting

    • indices

      GET /_search
      {
      "query": {
      "constant_score" : {
      "filter" : {
      "term" : { "user" : "kimchy"}
      },
      "boost" : 1.2
      }
      }
      }

    联合查询(Joining queries)

    • Nested

    • Has Child

    • Has Parent

    • Parent Id

      GET /_search
      {
      "query": {
      "constant_score" : {
      "filter" : {
      "term" : { "user" : "kimchy"}
      },
      "boost" : 1.2
      }
      }
      }

  • 相关阅读:
    scala之伴生对象的继承
    scala之伴生对象说明
    “Failed to install the following Android SDK packages as some licences have not been accepted” 错误
    PATH 环境变量重复问题解决
    Ubuntu 18.04 配置java环境
    JDBC的基本使用2
    DCL的基本语法(授权)
    ZJNU 1374
    ZJNU 2184
    ZJNU 1334
  • 原文地址:https://www.cnblogs.com/lilongsy/p/6654490.html
Copyright © 2011-2022 走看看