在 elasticsearch 中通过别名搜索时如何引用各个索引中的特定字段?
How to reference particular fields in the individual indices when searching through alias in elasticsearch?
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这三个指数的别名。
此搜索将仅搜索三个索引中最主要的字段。字段包括:
公司指数:
- 被保险人姓名
- 教唆者
公司被保险人指数:
- 姓名
公司档案索引:
- 姓名
在上面的代码中,我只是为三个索引创建了查询字段。我想分成三个指数。
如果您的文档中有 _index
字段,有一种方法可以做到这一点。
{
"query":{
"bool":{
"should": [{
"terms":{
"_index":["company_insureds"]
}},
{
"term":{
"name":"nameValue"
}
}
]
}
}
}
实现其他领域的东西,可以参考
如果您的索引中没有 _index
,则无法执行此操作。
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这三个指数的别名。
此搜索将仅搜索三个索引中最主要的字段。字段包括:
公司指数:
- 被保险人姓名
- 教唆者
公司被保险人指数:
- 姓名
公司档案索引:
- 姓名
在上面的代码中,我只是为三个索引创建了查询字段。我想分成三个指数。
如果您的文档中有 _index
字段,有一种方法可以做到这一点。
{
"query":{
"bool":{
"should": [{
"terms":{
"_index":["company_insureds"]
}},
{
"term":{
"name":"nameValue"
}
}
]
}
}
}
实现其他领域的东西,可以参考
如果您的索引中没有 _index
,则无法执行此操作。