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
      }
      }
      }

  • 相关阅读:
    Java SE 第十二,三,四,五六讲 Java基础知识回顾
    Java SE第二十一 抽象类
    Java SE 第二十讲 static与final关键字详解
    使用AspNetPager分页的范例
    AJax错误"WebForm1"没有定义的javascript错误的解决方法
    如何为自定义的控件在工具箱中自定义个性化的图标
    C#面向对象名词比较(转ttyp 的文章)
    vs2003自带的报表使用load("rpt.rpt")方式,显示不出报表工具的图片解决方案
    DropDownlist常见的小错误
    Ajax获取数据库中的字段
  • 原文地址:https://www.cnblogs.com/lilongsy/p/6654490.html
Copyright © 2011-2022 走看看