弹性搜索-尝试以递归方式触发搜索API [英] Elastic search - trying to trigger search api in recursive way

查看:50
本文介绍了弹性搜索-尝试以递归方式触发搜索API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在弹性搜索中,我确实想进行递归搜索.像基于第一个查询结果一样,我必须触发下一个查询(第一个查询结果是第二个查询的输入).它应该一直查询直到结果为 null .

In elastic search i do want to do a recursive kind of search. Like based on first query result, i have to fire the next query ( first query result is the input of second query). It should keep on query till the result comes as null.

例如:

来自下表数据.

如果要搜索值 car ,则应提供 id value ,并应检查 parent_id .然后,输入 parent_id ,它应该再次检查 id value .

if am searching for the value car, it should give the id and value and should check for the parent_id. Then, parent_id is the input and it should check for id and value again.

同样,它应该直到 parent_id null 为止.

Likewise, it should go till parent_id is null.

id      Parent_id       Value
1       null            null
2       45              Hundai
3       89              Volvo
4       1               Benz
5       3               Audi
6       4               BMW
7       6               car

如果我搜索值 car ,我应该获得以下详细信息.

If i search for a Value car i should get the following details.

id      Value
7       car
6       BMW
4       Benz
1       null

推荐答案

您正在寻找的解决方案实际上是 SELF JOIN 操作.

The solution you are looking for is actually SELF JOIN operation.

您可以参考此链接,因为您可以通过多个级别的父级对数据进行建模,但是请记住,这会带来很高的查询成本.同样,不应使用我们在 RDBMS 中对数据建模的方式来对 elasticsearch 中的文档进行建模.

You can refer to this link as how you can model your data via multiple levels of parents but keep in mind that it comes at a very high querying cost. And again, the documents in elasticsearch shouldn't be modeled the way we model the data in RDBMS.

您所能做的就是以 denormalized 的方式对文档建模,并将该信息存储为单独的字段.

What you can do is to have your documents modeled in denormalized way, and store that information as separate field.

例如您可以有一个名为 hierarchy 的字段,如下面的文档所述,该字段将在 indexing 操作期间创建,并使用简单的查询来获取您要查找的结果.

For e.g. you can have a field called as hierarchy as mentioned in the below document which is to be created during indexing operation and use simple querying to fetch the results you are looking for.

POST tempindex/1
{
  "id": 7,
  "name": "Car",
  "parentid": 6,
  "hierarchy": "7/6/5/2/1/null"
}

然后您可以简单地执行以下查询工作,该查询将为您返回以 null

And then you can simply have the below query work for you which would return you the list of documents which ends with null

GET tempindex/_search
{
  "query": {
    "match": {
      "hierarchy": "null"
    }
  }
}

这篇关于弹性搜索-尝试以递归方式触发搜索API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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