繁体   English   中英

如何像Solr一样在ElasticSearch中使用相同类型或索引的连接

[英]How to use join at a same type or index in ElasticSearch like solr

现在我遇到一个问题,因为我需要从名为“产品”的类型(或索引)中查询一些数据,并且我有三个参数($ p1,$ p2,$ p3),这些参数可以确定一些类别,然后我需要获取所有这些类别中的产品。 我知道如何在MySQL中这样完成:

select * 
from product 
where catagory in (
    select catagory 
    from product
    where p1 = $p1 and p2=$p2 and p3=$p3
)

我知道我可以像这样

{!join from=catagory to=catagory}p1:$p1 AND p2:$p2 AND p3:$p3

但是我想知道如何在ElasticSearch中做到这一点。

顺便说一句,对不起,我的泳池英语。 感谢您的帮助。

在查看了官方文档之后,可以像下面这样解决:
1.用联接类型创建索引

put /product
     {
        "mappings":{
            "cata" : {
                "properties" : {
                     "join_field": { 
                          "type": "join",
                          "relations": {
                            "header": "line" 
                          }
                        }
                }
            }
        }
     } 
  1. 创建标题数据

    发布/产品

     { "p1":"1", "p2":"2", "p3":"3", "join_field":"header" } 

    返回“ _id:” xxx“

  2. 创建线数据

post / cata?routing = xxx(!路由必须是标题的'_id',所以下面是'parent')

{
    "p1":"1",
    "p2":"1",
    "p3":"1",
    "other":"others...",
    "join_field":{
        "name": "line",
        "parent": "xxx"
  }
}  

4.查询数据
发布/ cata / _search
{ "query": { "has_parent" : { "parent_type" : "header", "query" : { "has_child" : { "type" : "line", "query" : { "term" : { "other" : "others..." } } } } } } }

上面的方法解决了我的问题

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM