/ /条件付き(フィールドの同じ値)に基づいて返されるトップスコア結果の制限ElasticSearch Aggregations - search、lucene、elasticsearch、search-engine

ElasticSearch Aggregations - 検索、lucene、elasticsearch、検索エンジン(フィールドの同じ値)

特定のフィールドで同じ値を持つドキュメントの_scoreに基づいて上位2つの結果のみをプルする方法はありますか?

このフィルタまたはアグレゲーションの前のヒットは以下のようになります:

{
"_index":"myindex",
"_score":100,
"_source": {
"myfield1": "i have a twin",
"name":"fred"
}
},

{
"_index":"myindex",
"_score":50,
"_source": {
"myfield1": "i have a twin",
"name":"george"
}
},

{
"_index":"myindex",
"_score":10,
"_source": {
"myfield1": "i have a twin",
"name":"tom"
}
},

{
"_index":"myindex",
"_score":10,
"_source": {
"myfield1": "i DONT have a twin",
"name":"doug"
}
}

その後、このフィルタ/ aggの後に、私はこれを望んでいます...彼はmyfield1と同じ値を持っているが、最低のスコアを持っているため、削除されました。 Dougはmyfield1とは異なる値を持っているので、そのままです。

{
"_index":"myindex",
"_score":100,
"_source": {
"myfield1": "i have a twin",
"name":"fred"
}
},

{
"_index":"myindex",
"_score":50,
"_source": {
"myfield1": "i have a twin",
"name":"george"
}
},

{
"_index":"myindex",
"_score":10,
"_source": {
"myfield1": "i DONT have a twin",
"name":"doug"
}
}

これが正しい効果を期待していましたが、それはできませんでした。

{
"query": {
"function_score": {
"query": {
"bool": {
"should": [
{
"match_phrase_prefix": {
"myfield1": {
"query": "i have",
"fuzziness": 1,
"slop": 2,
"max_expansions": 10,
"prefix_length": 1
}
}
}
]
}
},
"boost_mode": "replace",
"functions": [
{
"script_score": {
"script": "_score * [...] "
}
}
]
}
},
"aggs": {
"myfield1": {
"terms": {
"field": "myfield1",
"size": 2,
"order": {
"max_score": "desc"
}
},
"aggs": {
"max_score": {
"max": {
"field": "_doc.score"
}
}
}
}
}
}

回答:

回答№1は0

与えられた2つの答えしか得られないようにするクエリには、パラメータ "size"を含めるようにしてください:2はaggsの外にあります(あなたの例ではクエリとaggsと同じレベルにあります)。 sizeパラメータは、ESに何回回答したいか(つまり、何件の検索結果が要求されているか)を示します。最初の部分は2でなければなりません。

"query":{...}、

...他のもの... 、

「サイズ」:2

指定したクエリ(最初のヒット)に対して2ヒットを得るはずです。

また、私は確信していませんが、あなたのように見えます基本的に文書を検索して文書を返すことを望みます(あなたの望む結果はこれを示しています)。その場合、集計は必要ありません。検索結果のみが必要です。

したがって、基本的には、multi_searchエンドポイントを使用して2つの別々の検索リクエストを送信することができます(http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-multi-search.html

希望が役立ちます。