2016-07-21 7 views
0

Ich habe eine Funktion_Score-Abfrage mit 2 Zerfallsfunktionen (beide Gauss) und script_score Funktion. In der script_score-Funktion füge ich einige Punkte hinzu und multipliziere sie. Jetzt möchte ich das Ergebnis mit der Gauss-Funktion (dem Ort) multiplizieren und dann zusammen mit der anderen Gauss-Funktion (dem creation_date) hinzufügen. Ich möchte das tun, um den neueren Dokumenten einen Schub zu geben.elasticsearch Ist es möglich, score_mode für function_score zu kombinieren Abfrage

Wie kann ich das erreichen? Mit dem score_mode der function_score-Abfrage kann ich nur multiplizieren oder summieren.

{ 
    "query": { 
    "function_score": { 
     "functions": [ 
     { 
      "gauss": { 
      "location": { 
       "origin": { 
       "lon": 16.37, 
       "lat": 48.21 
       }, 
       "scale": "100km", 
       "offset": "15km", 
       "decay": 0.3 
      } 
      } 
     }, 
     { 
      "gauss": { 
      "creation_date": { 
       "scale": "30d", 
       "offset": "20d", 
       "decay": 0.1 
      } 
      } 
     }, 
     { 
      "script_score": { 
      "lang": "expression", 
      "script": "(((doc['value_a'].value + doc['value_b'] + 1) * boost_a) + (ln(sqrt(doc['value_c'].value + 1)) * boost_c))", 
      "params": { 
       "boost_a": 0.2, 
       "boost_b": 0.5 
      } 
      } 
     } 
     ], 
     "query": { 
     "match_all": {} 
     }, 
     "score_mode": "multiply", 
     "boost_mode": "multiply" 
    } 
    }, 
    "sort": { 
    "_score": "desc" 
    } 
} 

Vielen Dank im Voraus.

Antwort

2

Ich fand eine Lösung.

{ 
    "query": { 
    "function_score": { 
     "functions": { 
     "gauss": { 
      "creation_date": { 
      "scale": "30d", 
      "offset": "20d", 
      "decay": 0.1 
      } 
     } 
     }, 
     "query": { 
     "function_score": { 
      "functions": [ 
      { 
       "gauss": { 
       "location": { 
        "origin": { 
        "lon": 16.37, 
        "lat": 48.21 
        }, 
        "scale": "100km", 
        "offset": "15km", 
        "decay": 0.3 
       } 
       } 
      }, 
      { 
       "script_score": { 
       "lang": "expression", 
       "script": "(((doc['value_a'].value + doc['value_b'] + 1) * boost_a) + (ln(sqrt(doc['value_c'].value + 1)) * boost_c))", 
       "params": { 
        "boost_a": 0.2, 
        "boost_b": 0.5 
       } 
       } 
      } 
      ], 
      "query": { 
      "match_all": {} 
      }, 
      "score_mode": "multiply", 
      "boost_mode": "multiply" 
     } 
     } 
    }, 
    "score_mode": "multiply", 
    "boost_mode": "sum" 
    }, 
    "sort": { 
    "_score": "desc" 
    } 
} 
Verwandte Themen