2017-05-08 19 views
0

私は壮大な子供を探している間、弾性検索のいくつかの奇妙な動作に直面しています。私の孫は親文書ごとにそれぞれを認識しません。親の子供たちを返すために弾性検索をすると、すべてのヒットを返します。それから、孫がいる子供たちを私に返すように頼むと、私は間違った結果を得ます。いくつかの時間私はヒットまたはそれ以下を取得します。しかし、私がグランド・チャイルドのルーティングと親IDを確認すると、彼らは彼らの親に存在することがわかりました。しかし、なぜ私は間違った結果を得ているのか理解できません。あなたの誰かがこの種の問題に遭遇しましたか? 。ElasticSearch:孫/子/親の関係が正しく機能していない

PUT/test_index

:私は三度私のコードをチェックし、私はこのエラーを再現するために、あなたに手順をお見せしましょう :-(いずれかのタイプのエラーが見つかりませんでした ここ

は私のマッピングです

{ "mappings":{ "parentDoc":{ "properties":{ "id":{ "type":"integer" }, "name":{ "type":"text" } } }, "childDoc": { "_parent": { "type": "parentDoc" }, "properties":{ "id":{ "type":"integer" }, "name":{ "type":"text" }, "contact": { "type":"text" } } }, "grandChildDoc": { "_parent": { "type": "childDoc" }, "properties":{ "id":{ "type":"integer" }, "description":{ "type":"text" } } } } } 

インデックスparentDoc:

PUT/test_index/parentDoc/1

{ 
    "pdId":1, 
    "name": "First parentDoc" 
} 

PUT/test_index/parentDoc/2

{ 
    "pdId":2, 
    "name": "Second parentDoc" 
} 

インデックスchildDoc:

PUT/test_index/childDoc/10?親= 1

PUT/test_index/childDoc/101親= 1

{ 
    "cdId":101, 
    "name": "Second childDoc", 
    "contact" : "+XX0000000111" 
} 

PUT/test_index/childDoc/20親= 2

{ 
    "cdId":20, 
    "name": "Third childDoc", 
    "contact" : "+XX0011100000" 
} 

インデックスgrandChildDoc:

PUT/test_index/grandChildDoc/100?親= 10

{ 
    "gcdId":100, 
    "name": "First grandChildDoc" 
} 

PUT/test_index/grandChildDoc/200?親= 10

{ 
    "gcdId":200, 
    "name": "Second grandChildDoc" 
} 

PUT/test_index/grandChildDoc/300?私は私にchildDocを持っているものをparentDocを表示するように弾性検索を要求したとき、親は= 20

{ 
    "gcdId":300, 
    "name": "Third grandChildDoc" 
} 

は今、それが返されます。 POST/test_index/parentDoc/_search

{ 
    "query": { 
     "has_child": { 
      "type": "childDoc", 
      "query": { 
       "match_all": {} 
      } 
     } 
    } 
} 

結果:(これは問題ありません!)

01私は私にgrandChildDocを持っているものをchildDocを表示するelasticsearchを頼むとき

は今、それが返されます。 POST/test_index/childDoc/_search

{ 
    "query": { 
     "has_child": { 
      "type": "grandChildDoc", 
      "query": { 
       "match_all": {} 
      } 
     } 
    } 
} 

結果:(ここでは、ヒットの一部が欠落していることがわかります。例えば、のidとの子ドックがあります。

{ 
    "took": 7, 
    "timed_out": false, 
    "_shards": { 
     "total": 5, 
     "successful": 5, 
     "failed": 0 
    }, 
    "hits": { 
     "total": 1, 
     "max_score": 1, 
     "hits": [ 
      { 
       "_index": "test_index", 
       "_type": "childDoc", 
       "_id": "20", 
       "_score": 1, 
       "_routing": "2", 
       "_parent": "2", 
       "_source": { 
        "cdId": 20, 
        "name": "Third childDoc", 
        "contact": "+XX0011100000" 
       } 
      } 
     ] 
    } 
} 

私は何をしているのですか?それともバグですか?任意の回避策または解決策???

[:私はelasticsearch V5.4を使用しています]

答えて

0

私は同じ作業を持っています。私は弾性のある文書を索引付けするためにlogstashを使用しています。

根本原因:

私は、根本的な原因を調査してきました。デフォルトでは、エラスティックは5つのシャードを割り当て、1組の親子チャイルドチャイルドは同じシャードに置かなければなりません。残念ながら、データは断片全体に分散されています。 Elasticは、同じシャード内にあるレコードのみを返します。

ソリューション:親子-孫が機能するためには

は、あなたが壮大な子ドキュメント内の値を、ルーティングなど壮大な親文書IDを持っている必要があります。

シングルレベル(親子)の場合、親の値は正常な結果を出力する値ではありません。しかし、3つのレベルでは、孫の各ドキュメントのルーティングを設定する必要があります。

私が言及したように、ルーティング値はgrand parent idでなければなりません。

logstashを使用して例の下に​​見つけてください:

  1. "index" => "search" 
    "document_type" => "parent" 
    "document_id" => "%{appId}" 
    
  2. 子供:親/ルーティングが親文書IDと同じであるため、デフォルトで動作します。式(shard_num =ハッシュ()%のnum_primary_shardsを_routing)

    "index" => "search" 
    "document_type" => "child" 
    "document_id" => "%{lId}" 
    "parent" => "%{appId}" 
    
  3. 孫ルーティング:ルーティングが同じにすべての文書この意志指数

    "index" => "search" 
    "document_type" => "grandchild" 
    "document_id" => "%{lBId}" 
    "parent" => "%{lId}" 
    "routing" => "%{appId}" 
    

グランド親文書IDであるAPPIDであることに注意してくださいシャードと検索はこのユースケースでうまく動作します。

関連する問題