gpt4 book ai didi

elasticsearch - 有没有办法在两次出现之间更改加法 Action ? (在 bool 查询中)

转载 作者:行者123 更新时间:2023-12-02 23:07:19 25 4
gpt4 key购买 nike

我有下一个查询:

curl -X POST "localhost:9200/_search?pretty" -H 'Content-Type: application/json' -d'
{
"query": {
"bool" : {

"must" :
{ "term" :
{ "message" :
{
"value": "message",
"boost": 2.0
}
}
},
"should" :
{ "term" :
{ "message" :
{
"value": "message",
"boost": 2.0
}
}
}

}
}
}
'
我从此响应中获得的 _score_score的2倍(我没有任何范围( must / should)就得到了)
我的问题是是否可以将操作更改为多个,而不是添加 ,例如-代替 _score + _score,我将获得 _score * _score

最佳答案

您可以使用function score query
一个工作示例(使用脚本分数):_score将乘以_score 映射

PUT index
{
"mappings": {
"properties": {
"message": {
"type": "keyword"
}
}
}
}
插入文档
POST index/_doc/1
{
"message":"message"
}

POST index/_doc/2
{
"message":"message"
}
不包含script_score的搜索查询
GET index/_search
{
"query": {
"function_score": {
"query": {
"bool": {
"must": [
{
"term": {
"message": {
"value": "message"
}
}
}
],"should": [
{
"term": {
"message": {
"value": "message"
}
}
}
]
}
}
}
}
}
结果:
"hits" : [
{
"_index" : "index",
"_type" : "_doc",
"_id" : "3",
"_score" : 1.3862944,
"_source" : {
"message" : "message"
}
},
{
"_index" : "index",
"_type" : "_doc",
"_id" : "4",
"_score" : 1.3862944,
"_source" : {
"message" : "message"
}
}
]
使用script_score进行搜索查询
GET index/_search
{
"query": {
"function_score": {
"query": {
"bool": {
"must": [
{
"term": {
"message": {
"value": "message"
}
}
}
],"should": [
{
"term": {
"message": {
"value": "message"
}
}
}
]
}
},
"script_score": {
"script": {
"source": "_score"
}
}
}
}
}
结果
"hits" : [
{
"_index" : "index",
"_type" : "_doc",
"_id" : "3",
"_score" : 1.921812,
"_source" : {
"message" : "message"
}
},
{
"_index" : "index",
"_type" : "_doc",
"_id" : "4",
"_score" : 1.921812,
"_source" : {
"message" : "message"
}
}
]

关于elasticsearch - 有没有办法在两次出现之间更改加法 Action ? (在 bool 查询中),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64314713/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com