2017-02-14 53 views
0

在弹性搜索我需要所有其用户ID的距离执行这样子查询中ElasticSearch

{ 
"size": 200, 
"query": { 
    "bool": { 
     "must": { 
      "match": { 
       "targetId": { 
        "query": 1234 
       } 
      } 
     } 
    } 
}, 
"_source": { 
    "includes": [ 
     "userId" 
    ], 
    "excludes": [] 
} 
} 

另一elasticsearch查询结果的文件。如果在SQL执行将有一个类似楼下的查询。


select * from mytable where userId in (select userId from mytable where targetId = 1234); 

但我'无法形成类似elasticsearch查询,有没有elasticsearch执行子查询的其他一些 方式。

为了阐述这个问题,我已经添加下面

"hits": [ 
    { 
     "_index": "idx0", 
     "_type": "1234", 
     "_id": "1235-1486716882293", 
     "_source": { 
      "targetid": "42644", 
      "userid": "15784334830333693", 
     } 
    }, 
    { 
     "_index": "idx0", 
     "_type": "1234", 
     "_id": "1235-1486716882293", 
     "_source": { 
      "data": { 
       "info":"user data available" 
      }, 
      "userid": "15784334830333693", 
     } 
    }, 
    { 
     "_index": "idx0", 
     "_type": "1234", 
     "_id": "1235-1486716882293", 
     "_source": { 
      "data": { 
       "info":"user data available" 
      }, 
      "userid": "00000034830333693", 
     } 
    } 
    ] 

数据为u从以上数据可以看出,用户文档具有只包含用户ID数据,谁已经实现了目标用户的信息存储在具有targetid和userid的另一个文档中。

要找出谁是已实现的目标用户,我需要执行两个查询使用目标ID 1.get用户ID ES,我有, 2.注册有从以前的查询用户标识的所有文件。

是否有任何其他方式在单个查询中执行此操作。

+0

您可能会失去使用[术语查找机制](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-terms-query.html#query-dsl-terms -抬头) – Val

回答

1

ES中不允许内部联接。来自RDBMS的世界很难涉及,但关系是速度的折衷。

ES有处理关系的各种其他方式,详细讨论here