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中的内容,具体问题有待解决

  • 相关阅读:
    关于在MAC上进行 LARAVEL 环境 Homestead 安装过程记录
    js 贷款计算器
    js 实现阶乘
    js 两点间距离函数
    composer Your requirements could not be resolved to an installable set of packages
    vue 项目优化记录 持续更新...
    vue 项目打包
    vue 真机调试页面出现空白
    vue 真机调试
    谈谈-Android状态栏的编辑
  • 原文地址:https://www.cnblogs.com/m-bianbian/p/9006191.html
Copyright © 2011-2022 走看看