【问题标题】:elasticsearch : boosting documents in has_parent queryelasticsearch:在 has_parent 查询中提升文档
【发布时间】:2014-09-03 22:37:30
【问题描述】:

有没有办法提升来自has_parent 查询的文档?

{
  "query": {
      "function_score": {
          "query": {
              "bool": {
                  "should": [
                      {
                          "multi_match": {
                              "fields": ["name^3", "tags^2", "content"],
                              "query": "xx"
                          }
                      },
                      {
                          "has_parent": {
                              "type": "theparent",
                              "query": {
                                  "multi_match": {
                                      "type": "best_fields",
                                      "fields": ["name^5", "content"],
                                      "query": "xx"
                                  }
                              }
                          }
                      },
                      {
                          "has_child": {
                              "type": "thechild",
                              "query": {
                                  "multi_match": {
                                      "fields": ["name^3","content"],
                                      "query": "xx"
                                  }
                              }
                          }
                      }
                  ]
              }
          },
          "score_mode": "sum",
          "functions": [
              {
                  "linear": {
                      "date": {
                          "origin": "2014-08-29",
                          "scale": "700d",
                          "decay": 0.6
                      }
                  }
              }
          ]
      }
  }

更准确地说,我只想在查询与父级的名称字段匹配时提升这些文档 (我还没有找到一种方法来引用 functions 中的父字段,即 theparent._source.name ~= "xx"

【问题讨论】:

    标签: elasticsearch


    【解决方案1】:

    根据sources from Github (see line 104)boost 参数允许在has_parent 查询中使用。

    基于此属性,您可以专门提升包含has_parent 查询的should 子句。在您的情况下,结果将是:

    ...
                      {
                          "has_parent": {
                              "type": "theparent",
                              "query": {
                                  "multi_match": {
                                      "type": "best_fields",
                                      "fields": ["name^5", "content"],
                                      "query": "xx"
                                  }
                              },
                              "boost": 5
                          }
                      }
    ...
    

    我不知道它是否可以帮助你,但你会发现更多关于提升查询子句的见解here

    【讨论】:

    • 你说得对。我将 boost 参数设置在错误的级别。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多