2017-11-10 5 views
5

ElasticSearch 5.6.3にネストされたドキュメントの集計に問題があります。ElasticSearch 5.6.3でネストされたドキュメントの集計を取得すると、Lucene例外が発生する

私のクエリは次のように構成されています。私は(そしてもちろん削除ネストされたAGGで)非ネストされたフィールドに集計をしてみてください

query 
    aggs 
    |_filter 
    |_nested 
     |_term 
     |_top-hits 

場合、期待どおり、すべてが動作します。それが今で構成されているようしかし、私はLuceneのから例外を受け取る: Child query must not match same docs with parent filter. Combine them as must clauses (+) to find a problem doc. docId=2147483647, class org.apache.lucene.search.ConstantScoreScorer

この例外はElasticSearch 2.4.6でトリガないです。

私は集計を別の方法で構造化しようとしましたが、うまくいく組み合わせを見つけ出すことができませんでした。

"recording": { 
    "dynamic": "strict", 
    "_all" : { 
    "enabled" : false 
    }, 
    "properties": { 
    "id": { 
     "type": "integer" 
    }, 
    "soloists": { 
     "properties": { 
     "type": "nested", 
     "person": { 
      "properties": { 
      "id": { 
      "type": "integer" 
      }, 
      "name": { 
       "type": "string", 
       "index": "not_analyzed" 
      } 
     } 
     } 
    }, 
    "work": { 
     "id": { 
     "type": integer 
     }, 
     "title": { 
     "type": "string", 
     "index": "not_analyzed" 
     } 
    } 
} 

とクエリ自体::

これは、マッピングがどのように見えるかです

{ 
    "query": {}, 
    "aggs": { 
    "my_top_results": { 
     "global": {}, 
     "aggs": { 
     "my_filter_agg": { 
      "filter": { 
      "bool": { 
       "must": [ 
       { 
        "bool": { 
        "should": [ 
         { 
         "nested": { 
          "path": "soloists", 
          "query": { 
          "bool": { 
           "must": { 
           "match": { 
            "soloists.person.id": 77957 
           } 
           } 
          } 
          } 
         } 
         } 
        ] 
        } 
       } 
       ] 
      } 
      }, 
      "aggs": { 
      "my_nested_agg": { 
       "nested": { 
       "path": "soloists" 
       }, 
       "aggs": { 
       "my_terms_agg": { 
        "term": { 
        "field": "soloists.person.id", 
        "size": 10 
        } 
        "aggs": { 
        "my_top_hits_agg": { 
         "size": 1, 
         "_source": { 
         "include": [ 
          "soloists.person.id", 
          "soloists.person.name" 
         ] 
         } 
        } 
        } 
       } 
       } 
      } 
      } 
     } 
     } 
    } 
    } 
} 

すべてのヘルプは高く評価されるだろう。

解決策を探している間、私は偶然見つけいくつかのリンク:

+1

Hey Claudiuはまず、 'my_top_hits_agg'が適切な場所にないこと、' my_terms_agg'集約の中に位置し、 'top_hits'キーワードが欠けていること、そうですか?私はクエリがまったく実行されるのに驚いています。 – Val

+0

ちょっと@Val!そのような偶然のような会合。あなたはまったく正しい - それは私の側にコピーペーストエラーだった。ちょうどクエリを修正しましたが、問題は残っています... – cvursache

+0

確かに;-)最小限必要なもの、つまりネストされたフィルタ(bool/must + bool/should部分を削除する)にフィルタを単純化するとどうなりますか? – Val

答えて

3

あなたのマッピングとクエリで、いくつかのタイプミスがあります。

ここでは、Elasticsearch 5.6.3のインスタンスで使用するとエラーを引き起こさない固定コマンドをいくつか示します。

キバナまたはLinux端末(この場合は最初の行を編集する必要があります)でコピー&ペーストして、Elasticsearchインスタンスでテストできます。

HOST=10.225.0.2:9200 

curl -XPUT "http://$HOST/an_index" 

curl -XPUT "http://$HOST/an_index/recording/_mapping" -H 'Content-Type: application/json' -d' 
{ 
    "dynamic": "strict", 
    "_all": { 
    "enabled": false 
    }, 
    "properties": { 
    "id": { 
     "type": "integer" 
    }, 
    "soloists": { 
     "type": "nested", 
     "properties": { 
     "person": { 
      "properties": { 
      "id": { 
       "type": "integer" 
      }, 
      "name": { 
       "type": "string", 
       "index": "not_analyzed" 
      } 
      } 
     } 
     } 
    }, 
    "work": { 
     "properties": { 
     "id": { 
      "type": "integer" 
     }, 
     "title": { 
      "type": "string", 
      "index": "not_analyzed" 
     } 
     } 
    } 
    } 
}' 

curl -XPOST "http://$HOST/an_index/recording/1" -H 'Content-Type: application/json' -d' 
{ 
    "id": 0, 
    "soloists": [ 
    { 
     "person": { 
     "id": 77957, 
     "name": "John doe" 
     } 
    }, 
    { 
     "person": { 
     "id": 1, 
     "name": "Jane smith" 
     } 
    } 
    ], 
    "work": { 
    "id": 0, 
    "title": "Test" 
    } 
}' 

curl -XGET "http://$HOST/an_index/recording/_search?pretty" -H 'Content-Type: application/json' -d' 
{ 
    "size": 0, 
    "aggs": { 
    "my_top_results": { 
     "global": {}, 
     "aggs": { 
     "my_filter_agg": { 
      "filter": { 
      "bool": { 
       "must": [ 
       { 
        "bool": { 
        "should": [ 
         { 
         "nested": { 
          "path": "soloists", 
          "query": { 
          "bool": { 
           "must": { 
           "match": { 
            "soloists.person.id": 77957 
           } 
           } 
          } 
          } 
         } 
         } 
        ] 
        } 
       } 
       ] 
      } 
      }, 
      "aggs": { 
      "my_nested_agg": { 
       "nested": { 
       "path": "soloists" 
       }, 
       "aggs": { 
       "my_terms_agg": { 
        "terms": { 
        "field": "soloists.person.id", 
        "size": 10 
        }, 
        "aggs": { 
        "my_top_hits_agg": { 
         "top_hits": { 
         "size": 1, 
         "_source": { 
          "include": [ 
          "soloists.person.id", 
          "soloists.person.name" 
          ] 
         } 
         } 
        } 
        } 
       } 
       } 
      } 
      } 
     } 
     } 
    } 
    } 
}' 

これらのクエリが動作している場合ではなく、あなたのインデックスに適用された場合、我々はあなたのインデックスの正確な設定とマッピングを確認することができるように、あなたがcurl -XGET "http://$HOST/your_index_name"の出力にあなたの質問を更新してくださいだろうか?このようなエラーは、同じインデックスの型間の競合によって発生する可能性があります。私はそれに応じて私の答えを更新します。

+0

ありがとう@Pandawan!私は最終的に私たちのビジネスロジックに合った全く異なる方法でクエリを解決しました。いずれにしても、回答はおかげさまで、遅れて申し訳ありません。 – cvursache

関連する問題