2014-08-29 99 views
0

有没有办法提高从has_parent查询中“来”的文档?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 
         } 
        } 
       } 
      ] 
     } 
    } 

更确切地说,我想会提高那些文档只有当查询父 的名称字段匹配(我还没有找到一种方法来引用父字段中functionstheparent._source.name ~= "xx"

回答

1

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

根据此属性,可以专门增强包含has_parent查询的should子句。在你的情况,结果将是:

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

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

+0

你说得对。我把boost参数放在了错误的级别。 – fxbois 2014-09-17 16:36:20