chr*_*667 2 postgresql elasticsearch logstash elasticsearch-plugin logstash-configuration
简单的问题:我的弹性搜索引擎中有多个索引,由 postgresql 使用 logstash 镜像。ElasticSearch 在模糊搜索方面表现良好,但现在我需要在索引中使用引用,这些引用需要由查询处理。
Index A:
{
name: "alice",
_id: 5
}
...
Index B:
{
name: "bob",
_id: 3,
best_friend: 5
}
...
Run Code Online (Sandbox Code Playgroud)
我如何查询:
获取字段名称以“b”开头的索引B和名称以“a”开头的“best_friend”引用的索引A的每个匹配项
弹性搜索甚至可以做到这一点吗?
是的,这是可能的:POST A,B/_search
将查询多个索引。
为了匹配来自特定索引的记录,您可以使用元数据字段 _index
下面是一个查询得到指数B的每一场比赛与现场名称以“B”和索引的名称从“a”,但不匹配的参考,你通常做在关系SQL数据库。Elastic 中的外键引用匹配(连接)和每个 NoSQL 都是您的责任 AFAIK。请参阅Elastic Definitive Guide以找出满足您需求的最佳方法。最后,NoSQL 不是 SQL,请改变主意。
POST A,B/_search
{
"query": {
"bool": {
"should": [
{
"bool": {
"must": [
{
"prefix": {
"name": "a"
}
},
{
"term": {
"_index": "A"
}
}
]
}
},
{
"bool": {
"must": [
{
"prefix": {
"name": "b"
}
},
{
"term": {
"_index": "B"
}
}
]
}
}
]
}
}
}
Run Code Online (Sandbox Code Playgroud)