我找到了有关等效运算符的问题:
Elasticsearch:在Elasticsearch中的等效运算符中
,但我会找到相当于另一个更复杂的请求:
SELECT * FROM table WHERE id IN (SELECT id FROM anotherTable WHERE something > 0);
映射:
第一个索引:
{
"mappings": {
"products": {
"properties": {
"id": { "type": "integer" },
"name": { "type": "text" },
}
}
}
}
第二个索引:
{
"mappings": {
"reserved": {
"properties": {
"id": { "type": "integer" },
"type": { "type": "text" },
}
}
}
}
我想获得保留索引中包含ID的产品,并具有储备金的特定类型。
第一步 - 从reserved
索引获取所有相关ID:
{
"size": 0,
"query": {
"bool": {
"must": [
{
"term": {
"type": "TYPE_HERE"
}
}
]
}
},
"aggregations": {
"ids": {
"terms": {
"field": "id"
}
}
}
}
->请参阅:术语聚合,bool查询和术语查询。
-> _source
仅检索相关字段id
。
第二步 - 从products
索引获取所有相关文档:
{
"query": {
"bool": {
"must": [
{
"terms": {
"id": [
"ID_1",
"ID_2",
"AND_SO_ON..."
]
}
}
]
}
}
}
->将所有ID从第一步中拿出来,并将它们作为terms:id[...]
->参见术语QUERY。