ElasticSearch 如何实现将多索引的查询结果合并

想要实现的效果

想在ElasticSearch中通过dsl实现与下面sql语句相等的效果:
select user_name,user_code from table1 where user_name like '张%'
union all
select usrname as user_name,usrcode as user_code from table2 where usrcode like '10%'

最终的结果就是把不同索引的查询结果合并到一块,各索引中的字段名可能有不同。

求指点,谢谢!

谢谢回复!
我在不同的两个索引中分别查出如下数据:

img

我是想在ElasticSearch中通过dsl,实现如下效果:

img


感谢!

Elastic是文档数据库,其对数据结构一般发生在index time而确定而非runtime,一般可采取 enrich processor来完成数据结构重组,我博客里有完整教程。如果非要在检索时对结果集重组。可尝试使用runtime_fields结合scripts

es的优势是全文检索,耗时操作一般会在索引创建的时候进行处理。从设计理念上是不支持这样操作的。当然es也提供了SQL translate功能

望采纳,其实挺简单的,用minimum_should_match

{
  "query": {
    "bool": {
      "should": [
        {"prefix": {
          "user_name": {
            "value": "张"
          }
        }},
        {
          "prefix": {
            "usrcode": {
              "value": "10"
            }
          }
        }
      ],
      "minimum_should_match": 1
    }
  }
}