我需要一个转换成弹性查询以下SQL的帮助select * from index1where column1 not in(select column4 from index1)and column2= Value3.
应该只返回第三行我试过使用脚本语言。但我是比较新的。我无法得到的结果
zynd9foi1#
1.可以使用SQL search API1.您可以使用the boolean query合并多个查询。
POST test_sql/_bulk?refresh {"index":{"_id":"1"}} {"column1":"1","column2":"value3","column3":"value1","column4":""} {"index":{"_id":"2"}} {"column1":"2","column2":"value2","column3":"value2","column4":"1"} {"index":{"_id":"3"}} {"column1":"3","column2":"value3","column3":"value3","column4":""} GET test_sql/_search { "query": { "bool": { "must": [ { "term": { "column2": "value3" } } ], "must_not": [ { "terms": { "column1": { "index": "test_sql", "path": "column4", "id": "2" } } } ] } } }
这是Elasticsearch的搜索查询。它在“test_sql”索引中查找“column2”字段中的值为“value3”的文档。它还排除了“column1”字段中的值与ID为“2”的特定文档中的“column4”字段的值相匹配的文档。检查column4字段值“_id”=2 =〉该值为1。排除值等于1的文档。“_id”=1排除,因为“column1”:“1”。
The more simple explanation for this query: If a column4 value is equal to the column1 value exclude the document.
注意:在Elasticsearch中,terms查询不可能排除多个字段文档值。
terms
1条答案
按热度按时间zynd9foi1#
1.可以使用SQL search API
1.您可以使用the boolean query合并多个查询。
示例如下
这是Elasticsearch的搜索查询。它在“test_sql”索引中查找“column2”字段中的值为“value3”的文档。它还排除了“column1”字段中的值与ID为“2”的特定文档中的“column4”字段的值相匹配的文档。
检查column4字段值“_id”=2 =〉该值为1。排除值等于1的文档。“_id”=1排除,因为“column1”:“1”。
注意:在Elasticsearch中,
terms
查询不可能排除多个字段文档值。