gpt4 book ai didi

elasticsearch - SQL语句的等效Elasticsearch DSL语法

转载 作者:行者123 更新时间:2023-12-03 02:02:03 24 4
gpt4 key购买 nike

我正在尝试在 Elasticsearch 查询中复制以下查询逻辑,但是有些不正确。

基本上,以下查询返回一个文档。我想要应用第一个条件:"name": "iphone" 另一个更复杂的条件是(username = 'gogadget' AND status_type = '1' AND created_time between 4532564 AND 64323238)。请注意,嵌套 bool(boolean) 必须在应当位于内部的情况下才能处理更复杂的情况。如果我将"name": "iphone"的外部匹配更改为"name": "wrong value",我仍然应该看到1个文档。但是当我这样做的时候我一无所获。我不确定这哪里错了。

SQL查询在下面。

SELECT * from data_points 
WHERE name = 'iphone'
OR
(username = 'gogadget' AND status_type = '1' AND created_time between 4532564 AND 64323238)


{
"size": 30,
"query": {
"bool": {
"must": [
{
"bool": {
"minimum_should_match": "1",
"should": [
{
"bool": {
"must": [
{
"match": {
"username": "gogadget"
}
},
{
"terms": {
"status_type": [
"3",
"4"
]
}
},
{
"range": {
"created_time": {
"gte": 20140712,
"lte": 1405134711
}
}
}
]
}
}
],
"must": [],
"must_not": []
}
},
{
"match": {
"name": "iphone"
}
}
]
}
}
}

最佳答案

should查询将匹配查询并返回。

您不需要使用must来聚合OR query

查询应为:

{
"query": {
"bool": {
"should": [{
"bool": {
"must": [{
"match": {
"username": "gogadget"
}
}, {
"terms": {
"status_type": [
"3",
"4"
]
}
}, {
"range": {
"created_time": {
"gte": 20140712,
"lte": 1405134711
}
}
}]
}
}, {
"match": {
"name": "iphone"
}
}]
}
}
}

关于elasticsearch - SQL语句的等效Elasticsearch DSL语法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31373493/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com