在弹性搜索中搜索子女 [英] searching child-parent in elasticsearch

查看:140
本文介绍了在弹性搜索中搜索子女的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我在弹性搜索中有一个子代父母映射。
根据孩子的统计资料,我将如何去寻找父母。



示例:

  {
'parent':{
'_id':{
'path':'parent_id'
},
'属性':{
'parent_id':{
'type':'string'
},
'name':{
'type':'string '
},
'job':{
'type':'string'
},
'age':{
'type' '整数'
},

}
}
} {
'child':{
'_parent':{
'type':'parent'
},
'_id':{
'path':'child_id'
},
'properties':{
'child_id':{
'type':'string'
},
'name':{
'type':'string'
} ,
'favorite_toy':{
'type :'string'
},
'age':{
'type':'integer'
},

}
}
}

我将如何:




  • 将所有有孩子的父母叫做bob?

  • 计算所有有孩子名叫'bob'的父母? >
  • 得到所有有两个以上子女的父母?

  • 获得所有2名5岁以上的孩子的父母?


  • 解决方案

    1)和2) - 您可以简单地将查询包装到has_child查询中:

      {
    has_child:{
    type:child,
    query:{
    match:{
    name:bob
    }
    }
    }
    }

    3)和4) - 我不认为这是可能的。


    If I have a child-parent mapping in elastic search. How would I go about searching for parents based on statistics of their children.

    Example:

    {
      'parent':{
        '_id':{
          'path':'parent_id'
        },
        'properties':{
          'parent_id':{
            'type':'string'
          },
          'name':{
            'type':'string'
          },
          'job':{
            'type':'string'
          },
          'age':{
            'type':'integer'
          },
    
        }
      }
    }{
      'child':{
        '_parent':{
          'type':'parent'
        },
        '_id':{
          'path':'child_id'
        },
        'properties':{
          'child_id':{
            'type':'string'
          },
          'name':{
            'type':'string'
          },
          'favorite_toy':{
            'type':'string'
          },
          'age':{
            'type':'integer'
          },
    
        }
      }
    }
    

    How would I:

    1. get all the parents that have a child named 'bob'?
    2. count all the parents that have a child named 'bob'?
    3. get all the parents that have more than two children?
    4. get all the parents that have 2 children older than 5?

    解决方案

    1) and 2) - you can simply wrap your query into has_child query:

    {
      "has_child":{
        "type":"child",
        "query":{
          "match":{
            "name":"bob"
          }
        }
      }
    }
    

    3) and 4) - I don't think this is possible at the moment.

    这篇关于在弹性搜索中搜索子女的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆