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

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