2016-11-16 6 views
0

elasticsearchで私は、ターゲットのドメインに属するユーザーのメールが一致したことを確認する必要があり、私は2つのテーブル間のクエリを作ることができるように、私は次のテーブルを持っている2.3

Company: 
- id 
- name 
- domain 
- timestamp 

Target: 
- id 
- name 
- domain 
- company 
- website 
- company_id 
- timestamp 

User: 
- id 
- firstName 
- lastName 
- email 
- company_id 
- timestamp 

を2つのテーブルに一致するクエリを作成します。会社。

私は、Python 2.7

+0

:http://stackoverflow.com/質問/ 35153578/map-a-book-in-elasticsearch-many-levels-nested-vs-parent-child-relationshi/35153715#35153715 + http://stackoverflow.com/questions/40008948/elasticsearch-query-中間結果/ 40013303#40013303 + http://stackoverflow.com/questions/34477816/how-to-use-elasticsearch-to-get-join-functionality-as-in-sql/34477920#34477920 + http: //stackoverflow.com/questions/33288503/elasticsearch-map-two-sql-tables-with-a-foreign-key/33294753#33294753 – Val

答えて

0

Elasticsearch内の型はSQLのような相互に結合することができないとelasticsearch-PYライブラリとElasticSearch 2.3に取り組んでいます。しかし、親子関係を使って型同士を関連付けることができます。

多分あなたは次のように[会社]の子とクエリに[対象]と[ユーザー]テーブルを設定することができます。この場合:これらの答えは役立つかもしれない

"query": { 
    "bool": { 
     "must": [ 
      { 
       "has_child": { 
        "query": { 
         "match": { 
          "domain": "test domain" 
         } 
        }, 
        "child_type" : "Target" 
       } 
      }, 
      { 
       "has_child": { 
        "query": { 
         "match": { 
          "email": "test email" 
         } 
        }, 
        "child_type" : "User" 
       } 
      } 
     ], 
     "filter" : { 
      "term": { 
       "_type": "Company" 
      } 
     } 
    } 
} 
関連する問題