2015-12-25 28 views
0

對於文檔一樣當使用高斯衰減得分funtion,它總是成績1對嵌套元素

{ 
"_id" : "abc123", 
"_score" : 3.7613528, 
"_source" : { 
    "id" : "abc123", 
    "pricePeriods" : [{ 
      "periodTo" : "2016-01-02", 
      "eur" : 1036, 
      "gbp" : 782, 
      "dkk" : 6880, 
      "sek" : 9025, 
      "periodFrom" : "2015-12-26", 
      "nok" : 8065 
     }, { 
      "periodTo" : "2016-06-18", 
      "eur" : 671, 
      "gbp" : 457, 
      "dkk" : 4625, 
      "sek" : 5725, 
      "periodFrom" : "2016-01-02", 
      "nok" : 5430 
     }  ] 

} 
} 

我想對價格高斯衰減函數的分數。

我已經試過這樣

"query" : { 
    "function_score" : { 
     "functions" : [{ 
       "gauss" : { 
        "pricePeriods.dkk" : { 
         "origin" : "2500", 
         "scale" : "2500", 
         "decay" : 0.8 

        } 
       }, 
       "filter" : { 
        "nested" : { 
         "filter" : { 
          "range" : { 
           "pricePeriods.periodTo" : { 
            "gte" : "2016-03-17T00:00:00.000" 
           } 
          } 

         }, 
         "path" : "pricePeriods" 

        } 
       } 
      } 
      ] 

,似乎濾鏡找到我想要在高斯的價格,但最終得分始終爲1

解釋說

{ "value": 1, 
    "description": "min of:", 
    "details": [ 
    { 
     "value": 1, 
     "description": "function score, score mode [multiply]", 
      "details": [ 
        { 
       "value": 1, 
       "description": "function score, product of:", 
       "details": [ 
        { 
        "value": 1, 
         "description": "match filter: ToParentBlockJoinQuery (+ConstantScore(pricePeriods.periodTo:[[32 30 31 36 2d 30 33 2d 31 37 54 30 30 3a 30 30 3a 30 30 2e 30 30 30] TO *]) #QueryWrapperFilter(_type:__pricePeriods))", 
             "details": [] 
             }, 
             { 
             "value": 1, 
             "description": "Function for field pricePeriods.dkk:", 
             "details": [ 
              { 
               "value": 1, 
               "description": "exp(-0.5*pow(MIN[0.0],2.0)/1.4004437867889222E7)", 
               "details": [] 
              } 
             ] 
             } 
            ] 
           } 
          ] 
          } 

我可以看到here高斯顯然返回1時,它無法找到該字段。 但問題是爲什麼它無法找到嵌套文檔中的字段,以及如何ix。

回答

0

原因gauss function正在恢復1是因爲你說找不到領域,因爲它是nested,你基本上需要來包裝你的整個function_score查詢到nested query

{ 
    "query": { 
    "nested": { 
     "path": "pricePeriods", 
     "query": { 
     "function_score": { 
      "functions": [ 
      { 
       "gauss": { 
       "pricePeriods.dkk": { 
        "origin": "2500", 
        "scale": "2500", 
        "decay": 0.8 
       } 
       }, 
       "filter": { 
       "range": { 
        "pricePeriods.periodTo": { 
        "gte": "2016-03-17T00:00:00.000" 
        } 
       } 
       } 
      } 
      ] 
     } 
     } 
    } 
    } 
} 

這是否幫助?

+0

謝謝,但它仍然有兩個問題。 1:無論他們是否有價格,它仍然返回所有結果的分數1。 [鏈接](http://screencast.com/t/nDE7g6tLYV) 2:我無法添加父項的其他功能。 完整的查詢是一個相當複雜的與許多不同領域的分數。 但我不知道如何添加嵌套和頂級功能分數。 – ClausP

+0

我創建了一個測試索引,它起作用了,只給那些與條件不匹配的文檔給了1分。你正在使用什麼版本的ES? – ChintanShah25

+0

謝謝。似乎現在正在工作。我忘記了爲該功能添加權重,因此所有匹配gauss過濾器的文檔都排序在1以下。 通過添加一個wight,現在似乎得分更高。 我使用版本2.1.1和1.7 – ClausP