esDSL查询_随笔

查询方式

布尔查询和最佳匹配查询的区别

案例
布尔查询和最佳匹配查询的区别:两者使用类似。但是布尔查询的时候:评分时会让每个查询都去做一个计算最后取平均。而最佳匹配会找出最匹配的一个查询去做评分。

Named queries 命名查询

可以使用query字段对子查询进行标记。满足子查询的结果将被打上标记。
https://opster.com/guides/elasticsearch/search-apis/named-queries/

GET _search
{
   "query":{
      "bool":{
         "should":[
            {
               "multi_match":{
                  "query":"123",
                  "fields":[
                     "title",
                     "description"
                  ],
                  "_name":"match content"
               }
            },
            {
               "match":{
                  "product_id":{
                     "query":"123",
                     "_name":"match product id"
                  }
               }
            }
         ]
      }
   }
}

查询结果:

GET _search
{
   "query":{
      "bool":{
         "should":[
            {
               "multi_match":{
                  "query":"123",
                  "fields":[
                     "title",
                     "description"
                  ],
                  "_name":"match content"
               }
            },
            {
               "match":{
                  "product_id":{
                     "query":"123",
                     "_name":"match product id"
                  }
               }
            }
         ]
      }
   }
}

Boosting query

需要做降级处理时可以使用这个查询。(而不是一般查询的直接排除,只是降级)。
demo:

GET /_search
{
  "query": {
    "boosting": {
      "positive": {
        "term": {
          "text": "apple"
        }
      },
      "negative": {
        "term": {
          "text": "pie tart fruit crumble tree"
        }
      },
      "negative_boost": 0.5
    }
  }

其中需要查询的内容放到postive里面去。需要降级的字段放到negative去。negative_boost是一个0到1的浮点数。用于表示降级的程度。

constant_score query

查询相关性得分等于某值的结果。

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

Disjunction max query

类似于dismax query。

GET dis_max_index/_search
{
  "query": {
    "dis_max": {
      "tie_breaker": 0.1,
      "boost": 1.2,
      "queries": [
         {"match":{"title":"good key"}},
         {"match":{"name":"china"}}
      ]
    }
  }
}
  • tie_breaker
    这个参数可以把非最高匹配字段也加入到评分中来。

Function score query

略。
es官方文档

Span跨度查询

嵌套查询的升版:可以在嵌套查询的基础上规定文本内多查询的跨度关系

简书链接

es官网链接

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值