elasticsearch 一个字段的加权搜索和另一个字段的正常搜索,elasticsearch,kibana,elasticsearch,Kibana" /> elasticsearch 一个字段的加权搜索和另一个字段的正常搜索,elasticsearch,kibana,elasticsearch,Kibana" />

elasticsearch 一个字段的加权搜索和另一个字段的正常搜索

elasticsearch 一个字段的加权搜索和另一个字段的正常搜索,elasticsearch,kibana,elasticsearch,Kibana,我试图通过将搜索查询与标签或文档名称匹配来执行搜索,我在顶部还有一个过滤器,因此我必须使用must 这就是我一直在尝试的 { "query": { "bool": { "filter": { "term": { "type.primary": "audio" } }, "must": [ { "nested": { "path": "ta

我试图通过将搜索查询与标签或文档名称匹配来执行搜索,我在顶部还有一个过滤器,因此我必须使用
must

这就是我一直在尝试的

{
  "query": {
    "bool": {
      "filter": {
        "term": {
          "type.primary": "audio"
        }
      },
      "must": [
        {
          "nested": {
            "path": "tags",
            "score_mode": "sum",
            "query": {
              "function_score": {
                "query": {
                  "bool": {
                    "must": [
                      {
                        "match": {
                          "tags.tag": "big"
                        }
                      }
                    ]
                  }
                },
                "field_value_factor": {
                  "field": "tags.weight"
                },
                "boost_mode": "multiply",
                "boost": 10
              }
            }
          }
        },
        {
          "bool": {
            "must": [
              {
                "multi_match": {
                  "query": "big",
                  "fields": [
                    "name"
                  ],
                  "type": "phrase_prefix"
                }
              }
            ]
          }
        }
      ]
    }
  }
}
这只会导致空

如果我使用
should
而不是
must
查询可以正常工作,但它会使用
type.primary:audio
过滤器提供所有结果


我很确定还有其他方法可以搜索名称字段。谢谢。

你就快到了!在must中,您声明标记和名称都必须命中。请尝试以下操作:

GET /_search
{
  "query": {
    "bool": {
      "filter": {
        "term": {
          "type.primary": "audio"
        }
      },
      "must": [
        {
          "bool": {
            "should": [
              {
                "nested": {
                  "path": "tags",
                  "score_mode": "sum",
                  "query": {
                    "function_score": {
                      "query": {
                        "bool": {
                          "must": [
                            {
                              "match": {
                                "tags.tag": "big"
                              }
                            }
                          ]
                        }
                      },
                      "field_value_factor": {
                        "field": "tags.weight"
                      },
                      "boost_mode": "multiply",
                      "boost": 10
                    }
                  }
                }
              },
              {
                "multi_match": {
                  "query": "big",
                  "fields": [
                    "name"
                  ],
                  "type": "phrase_prefix"
                }
              }
            ]
          }
        }
      ]
    }
  }
}