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

    1.query string

    a).GET /index/type/_search  ===>>查询所有
    
    b).GET /index/type/_search?q=filed:value&sort=filed:desc  ===>> 以某个属性的值查询,并排序
    

    2. query dsl(Domain Specified Language 特定领域的语言)

    a).查询所有
    GET /index/type/_search
    {
         "query" : {
        "match_all" : {}
      }
    }
    b). 查询包含的值,同时排序
    GET /index/type/_search
    {
        "query":{
               "match"{
                     "filed"":"value"
                }
         },
         "sort":[
              {"filed": "desc"}
          ]
    
    }
    c).分页查询: from:从第几条开始,size:查询几条
    GET /index/type/_search
    {
           "query" :{ 
                "match_all":{}
           } ,
            "from":1,
            "size":1 
    }
    

    3.filter查询

    GET /index/type/_search
    {
        "query": {
            "bool": {
                "must": {
                    "match": {
                        "filed": "value"
                    }
                }, 
                "filter": {
                    "range": {
                        "filed": {
                            "gt": "value"
                        }
                    }
                }
            }
        }
    }
    

    4. 全文检索 (full-text search)

    GET /index/type/_search
    {
        "query" : {
            "match" : {
                "filed" : "value"
            }
        }
    }
    

    5. 短语搜索(phrase search)

    GET /index/type/_search
    {
        "query": {
            "match_phrase": {
                "filed": "value"
            }
        }
    }
    

     *注: 短语搜索与全文检索的区别: 全文检索的时候,会先将字段以空格拆分,如   aa bb,统计每个拆分的词在各个文档(document)中出现的次数,而后以查询的值匹配拆分的词的相关度,随后进行返回.   短语搜索则不会进行相关度匹配,必须完全符合才能匹配

    6. 高亮搜索(highlight search)

    GET /index/type/_search
    {
        "query": {
            "match": {
                "filed": "value"
            }
        }, 
        "highlight": {
            "fields": {
                "filed": { }
            }
        }
    }
    

      

    *:在kabana查询时:如果不小心将 GET 误写成 get  返回结果会产生差异,并且不执行query body中的内容,具体问题有待解决

  • 相关阅读:
    Windows 获取unix timestamp
    SQL Server 2008 R2:快速清除日志文件的方法
    mysql lost connection to server during query
    jquery 隐藏 显示 动画效果
    session
    javaScript日期
    路径惹的祸
    Declaration terminated incorrectly 讨厌 这样就不可以了
    jsp 调用其他jsp页面 跳转
    SQL 2008 启用和禁用xp_cmdshell
  • 原文地址:https://www.cnblogs.com/m-bianbian/p/9006191.html
Copyright © 2011-2022 走看看