如何在 ElasticSearch 中使用相同类型或索引的连接,例如 solr



现在我遇到了一个问题,因为我需要从名为"product"的类型(或索引)中查询一些数据,并且我有三个参数($p 1,$p 2,$p 3)可以确定一些类别,然后我需要获取这些类别中的所有产品。 我知道如何在MySQL中完成,如下所示:

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

我知道我可以像 solr 一样做到这一点

{!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?routeting=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..." } } } } } } }

以上方法解决我的问题

最新更新