我发现了关于IN等效运算符的问题:
ElasticSearch : IN equivalent operator in 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包含在保留索引中并且具有特定类型的保留。
答案 0 :(得分:0)
第一步 - 从delimiter $$
drop procedure if exists getfreenum $$
create procedure getfreenum(num int)
begin
set @compare := (num * 10);
set @maxId := (select sifra from artikli where sifra >= @compare order by sifra asc limit 1);
while @compare = @maxId do
set @compare := @compare + 1;
set @maxId = (select sifra from artikli where sifra >= @compare order by sifra asc limit 1);
end while;
select @compare;
end $$
delimiter ;
索引获取所有相关ID:
reserved
- >请参阅:Terms Aggregations,Bool Query和Term Query。
- > {
"size": 0,
"query": {
"bool": {
"must": [
{
"term": {
"type": "TYPE_HERE"
}
}
]
}
},
"aggregations": {
"ids": {
"terms": {
"field": "id"
}
}
}
}
只会检索相关字段_source
。
第二步 - 从id
索引获取所有相关文档:
products
- >从第一步中获取所有ID,并将它们作为{
"query": {
"bool": {
"must": [
{
"terms": {
"id": [
"ID_1",
"ID_2",
"AND_SO_ON..."
]
}
}
]
}
}
}
- >见Terms Query。