【问题标题】:How to reference particular fields in the individual indices when searching through alias in elasticsearch?在elasticsearch中通过别名搜索时如何引用各个索引中的特定字段?
【发布时间】:2020-06-21 13:54:28
【问题描述】:
const elasticsearch = new Client({ node: `http://localhost:9200` })

const response = await elasticsearch.search({
  index: companyIndex,
  body: {
    query:{
      query_string: {
        query: queryText,
        fields: ['name', 'insuredName', 'instigator']
      }
   }
  }
});

这里companyIndex是company-events、company-insureds、company-files三个指数的别名。 此搜索将仅搜索三个索引中最主要的字段。字段包括:

公司索引:

  • 被保险人姓名
  • 教唆者

公司被保险人指数:

  • 姓名

公司文件索引:

  • 姓名

在上面的代码中,我只是为三个索引创建了查询字段。我想分成三个索引。

【问题讨论】:

    标签: javascript node.js elasticsearch querydsl


    【解决方案1】:

    如果您的文档中有_index 字段,则有一种方法。

    {
      "query":{
        "bool":{
          "should": [{
            "terms":{
              "_index":["company_insureds"]
            }},
            {
             "term":{
              "name":"nameValue"
            }
          }
          ]
        }
      }
    }
    

    其他领域的东西可以参考multi-bool clause

    如果您的索引中没有_index,则无法执行此操作。

    【讨论】:

      猜你喜欢
      • 2017-12-24
      • 2018-08-01
      • 2016-09-07
      • 1970-01-01
      • 2014-12-08
      • 2023-04-08
      • 1970-01-01
      • 2013-07-03
      • 1970-01-01
      相关资源
      最近更新 更多