2014-08-29 95 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