现在我遇到了一个问题,因为我需要从名为' product‘的类型(或索引)中查询一些数据,并且我有三个参数( $p1,$p2,$p3)可以确定一些分类,然后我需要获取这些分类中的所有产品。我知道如何在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中做到这一点。
顺便说一句,很抱歉我的台球英语。我非常感谢你的帮助。
发布于 2018-05-15 19:01:14
在我查看了官方文档后,这可以像这样解决:
创建索引
put /product
{
"mappings":{
"cata" : {
"properties" : {
"join_field": {
"type": "join",
"relations": {
"header": "line"
}
}
}
}
}
} 发布/product
{ "p1":"1","p2":"2","p3":"3","join_field":"header“}返回"_id:"xxx”
“
发布/cata?routing=xxx (!路由必须是标头的'_id',因此是下面的'parent‘)
{
"p1":"1",
"p2":"1",
"p3":"1",
"other":"others...",
"join_field":{
"name": "line",
"parent": "xxx"
}
} post /cata/_搜索
{ "query": { "has_parent" : { "parent_type" : "header", "query" : { "has_child" : { "type" : "line", "query" : { "term" : { "other" : "others..." } } } } } } }
上面的方法解决了我的问题
https://stackoverflow.com/questions/50343864
复制相似问题