在Elasticsearch的结果分数中添加条件

如何解决在Elasticsearch的结果分数中添加条件

我正在与Elasticsearch合作,如果某个文档获得任何分数,我将获得所有结果。我想知道是否有任何方法可以使那些得分超过8的结果?

所以基本上我想给分数加上条件,我该怎么做?

我的查询如下:-

{
  "query": {
    "bool": {
      "filter": [
        {
          "match": {
            "haloha_id": "5f3028a92cae84015f42e242"
          }
        }
      ],"must": [
        {
          "match": {
            "text": {
              "query": "micromanage much. When allow people creative surprise you.","fuzziness": "auto","max_expansions":2
            }
          }
        }
      ],"should": [
        {
          "term": {
            "mood": {
              "value": 0
            }
          }
        }
      ]
    }
  }
}

我得到的结果是:-

{
    "took": 96,"timed_out": false,"_shards": {
        "total": 5,"successful": 5,"skipped": 0,"failed": 0
    },"hits": {
        "total": {
            "value": 90,"relation": "eq"
        },"max_score": 36.275604,"hits": [
            {
                "_index": "halohas","_type": "haloha","_id": "5f32dd3ca7d6503d21094572","_score": 36.275604,"_source": {
                    "haloha_id": "5f3028a92cae84015f42e242","text": "micromanage much. When allow people creative surprise you. ","mood": 0
                }
            },{
                "_index": "halohas","_id": "5f32e3d821091863d43c9ac2","_score": 8.826473,"text": "gave much when give.  ","mood": 3
                }
            },"_id": "5f329fe053205820993e1362","_score": 8.35145,"text": "creative stuff also  ","_id": "5f32de662fef9f420f284cb2","_score": 8.17037,"text": "capable much when focus make sure relax between  ","_id": "5f328efda5c79e3c7c0106b2","_score": 7.7291327,"text": "much consistent doing something when put much pressure myself. ","mood": 1
                }
            },"_id": "5f3323a345675c0dbe26e502","_score": 7.468121,"text": "put much bullshit most people  ","mood": 4
                }
            },"_id": "5f32f72130dccd4a7614ae32","_score": 7.159499,"text": "care much about people care all! ","_id": "5f333f73ef60df38131893f2","_score": 6.820949,"text": "need learn how relax myself. much better company when relaxed myself. ","_id": "5f3323695f2bf70e1625e152","_score": 6.731527,"text": "other people Don’t see judge sees you. kind love are!  ","_id": "5f32958074381f5248104592","_score": 6.7283688,"text": "work better when im people ","_id": "5f32bef887bb010202574fd2","_score": 6.2870326,"text": "waste time someone nothing you. ","mood": 5
                }
            },"_id": "5f330f6556aa9a6dc52778b2","_score": 6.27559,"text": "rely much external validation 'vomit mouth' others when stressed.  ","_id": "5f32f7b40507b252e14c2503","_score": 6.265601,"text": "worry much ","_id": "5f334980a0c525547a18bfb2","_score": 6.220806,"text": "deserve happy ? (and you! ?) ","mood": 2
                }
            },"_id": "5f33a17496e21420925574e2","_score": 5.5000744,"text": "don’t change much.   ","_id": "5f328b02589a6d6ad559cca2","_score": 5.364381,"text": "lot happier when make time own hobbies instead hanging out other people fun.  ","_id": "5f32cfa42d4f61445422fd62","_score": 5.234743,"text": "how much appreciate friends. ","_id": "5f32ad6b165c7619265cc142","_score": 5.096678,"text": "talk much,meaning listen enough.  ","_id": "5f32c9bbf1e3de05947e20d2","_score": 4.963728,"text": "eu sou capaz ","_id": "5f32903e90647f448366e022","_score": 4.8266034,"text": "don’t really social media much.  ","_id": "5f32f131c125c5029e739f62","_score": 4.807798,"text": "better day when good morning  ","_id": "5f3293c5c4bc755455653bf2","_score": 4.8031764,"text": "how much need quiet moments! ","_id": "5f335a1fd7230d48700bc022","_score": 4.7262926,"text": "spending time inside much thought did.  ","_id": "5f32e004f27723515e4897c2","_score": 4.719965,"text": "make do,happy,much less thought could. ","_id": "5f32b2d679e94a2e2f719332","_score": 4.6631713,"text": "much self confidence ever after started looking after myself. ","_id": "5f329a915609ca27e604bf54","_score": 4.6297007,"text": "much tougher anyone else is.  ","_id": "5f32e4bb6a8d684b312cbee2","text": "panic much,need build confidence ","_id": "5f3288900ef45a3b7c069712","_score": 4.619584,"text": "get inspired inspiring people ","_id": "5f330091c330f45f875b8b42","_score": 4.486246,"text": "when someone says it’s okay believe ","_id": "5f3292fe93cf4703ee5ccf82","_score": 4.4775033,"text": "perhaps enjoy own company little much... ","_id": "5f32e5745b57005d223f8562","_score": 4.423342,"text": "confident when positive. ","_id": "5f32a1a24ec504563e1beb52","_score": 4.4060936,"text": "how much I've missing doing things love.  ","_id": "5f32a9e2550bc549906bb2c2","_score": 4.365771,"text": "patient when comes certain things,others ","_id": "5f3288e4c1b11d31290a02c2","_score": 4.3149076,"text": "productive when want ","_id": "5f32d0bb98ed292e56443582","_score": 4.290538,"text": "definitely introvert need allow alone time future (ty lockdown helping realise that!) ","mood": 6
                }
            },"_id": "5f32d7711bdfa92dd5029742","_score": 4.2902403,"text": "put much effort making better person. ","_id": "5f32b677398fb37ecb7f1422","_score": 4.238718,"text": "set healthy boundaries.  love people fiercely sometimes end without much space energy own heart it’s needs. ","_id": "5f334ff53be251102d4c0c82","_score": 4.1381917,"text": "lack willpower when stressed ","_id": "5f3289e58698145fff135f54","_score": 4.093499,"text": "bad speaking front people thought was. ","_id": "5f3300bbc330f45f875b8b43","_score": 4.063119,"text": "people still even without facade. ","_id": "5f328cfee13b5e4812374a83","_score": 3.9950078,"text": "fear food freaking much change asap ): ","_id": "5f32c8c1f6d4033c646a1392","_score": 3.944161,"text": "procrastinate when scared failure ","_id": "5f328cd80c73b324466575a2","_score": 3.9116564,"text": "carrying lot weight “holding all together” much realized.  ","_id": "5f329531c4bc755455653bf3","_score": 3.807798,"text": "bounce back when life breaks ","_id": "5f32b55fd10ec57dbc4493c2","text": "feel better when eat better.  ","_id": "5f335864419088065f0de972","_score": 3.7673516,"text": "much control over emotions previously thought. willpower + awareness,totally shift own mood. ","_id": "5f3297f4083a101fb90c6cd2","_score": 3.7350545,"text": "when try... really try... can. ","_id": "5f330aee91d1873f0d168372","_score": 3.7010767,"text": "spend LOT time own best when project plan carry out. ","_id": "5f32c39d867c711119760c52","_score": 3.6320834,"text": "try hurt when mentally bad  ","_id": "5f32cae6b108c341950984c2","_score": 3.4654374,"text": "mom when come little patience parenting.  ","_id": "5f32ca96e439cc070b5350b2","_score": 3.4513555,"text": "offer advice people ask it. order honor others,listening more,asking reflective questions offering advice when requested ","_id": "5f32a693d76b001d4139d0e2","_score": 3.3657708,"text": "little tolerance when see someone integrity ","_id": "5f32ed684aec7215754c8882","text": "stronger realize when stay control emotions. ","_id": "5f3330e722abb82aa30a7c22","text": "become mentally unorganized when room mess ","_id": "5f32f089ae559d28c1493a32","_score": 3.3173094,"text": "it’s much harder motivated now,even though lot time hands ","_id": "5f33126a3f116d64e76a43c3","_score": 3.307673,"text": "how much living house traumatic memories kept grief stagnancy.Sold it,moved out Friday,felt deep release peace.Now,adventure!☺ ","_id": "5f32e20a91a5d205cd424612","_score": 3.2934766,"text": "keep going even when don’t want to.  ","_id": "5f32d2a6db59fd3aac5f7a72","_score": 3.2321246,"text": "tend quit things when they’re going expected ","_id": "5f32a0650bce1c6ae860e844","_score": 3.2045662,"text": "love stimulated mentally,love when friends,family,partner questioning beliefs see another perspective things  ","_id": "5f32b83eb491310ae7152bc2","_score": 3.139327,"text": "owe nobody looking \"beautiful\". physically ugly own it. body much aesthetics ","_id": "5f32a69d35bd071a206dedd2","_score": 1.0318205,"text": "come place life where no longer want deal other people's toxic junk. fix them. That's huge me. ? ","mood": 1
                }
            }
        ]
    }
}

解决方法

我得到了答案,我可以使用min_score添加条件

我在min_score之后的完整查询是:-

{
  "min_score": 8,"query": {
    "bool": {
      "filter": [
        {
          "match": {
            "haloha_id": "5f3028a92cae84015f42e242"
          }
        }
      ],"must": [
        {
          "match": {
            "text": {
              "query": "micromanage much. When allow people creative surprise you.","fuzziness": "auto","max_expansions":2
            }
          }
        }
      ],"should": [
        {
          "term": {
            "mood": {
              "value": 0
            }
          }
        }
      ]
    }
  }
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


依赖报错 idea导入项目后依赖报错,解决方案:https://blog.csdn.net/weixin_42420249/article/details/81191861 依赖版本报错:更换其他版本 无法下载依赖可参考:https://blog.csdn.net/weixin_42628809/a
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下 2021-12-03 13:33:33.927 ERROR 7228 [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPL
错误1:gradle项目控制台输出为乱码 # 解决方案:https://blog.csdn.net/weixin_43501566/article/details/112482302 # 在gradle-wrapper.properties 添加以下内容 org.gradle.jvmargs=-Df
错误还原:在查询的过程中,传入的workType为0时,该条件不起作用 <select id="xxx"> SELECT di.id, di.name, di.work_type, di.updated... <where> <if test=&qu
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct redisServer’没有名为‘server_cpulist’的成员 redisSetCpuAffinity(server.server_cpulist); ^ server.c: 在函数‘hasActiveC
解决方案1 1、改项目中.idea/workspace.xml配置文件,增加dynamic.classpath参数 2、搜索PropertiesComponent,添加如下 <property name="dynamic.classpath" value="tru
删除根组件app.vue中的默认代码后报错:Module Error (from ./node_modules/eslint-loader/index.js): 解决方案:关闭ESlint代码检测,在项目根目录创建vue.config.js,在文件中添加 module.exports = { lin
查看spark默认的python版本 [root@master day27]# pyspark /home/software/spark-2.3.4-bin-hadoop2.7/conf/spark-env.sh: line 2: /usr/local/hadoop/bin/hadoop: No s
使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams['font.sans-serif'] = ['SimHei'] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -> systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping("/hires") public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate<String
使用vite构建项目报错 C:\Users\ychen\work>npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-