2016-11-16 30 views
0

匹配查詢,我可以做2分表之間的查詢,我有以下表創建2代表與elasticsearch 2.3

Company: 
- id 
- name 
- domain 
- timestamp 

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

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

我需要的目標域,屬於用戶的郵件之間的匹配公司。

我的工作ElasticSearch 2.3與elasticsearch-PY庫與Python 2.7

+0

這些答案可能幫助:http://stackoverflow.com/問題/ 35153578/map-a-book-in-elasticsearch-with-many-levels-nested-vs-parent-child-relationshi/35153715#35153715 + http://stackoverflow.com/questions/40008948/elasticsearch-query- with-intermediate-results/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來加入。但是你可以使用父子關係讓類型相互關聯。

在這種情況下,也許你可以設置[目標]和[用戶]表[公司]的孩子和查詢,如:

"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" 
      } 
     } 
    } 
}