elasticsearch:在has_parent查询中提升文档

时间:2014-08-29 17:16:39

标签: elasticsearch

有没有办法提升“来自”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"

1 个答案:

答案 0 :(得分:1)

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

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

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

我不知道它是否对您有所帮助,但您会发现有关提升查询条款的更多见解here