You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

在AWS OpenSearch 1.3中如何实现ID、年龄范围及嵌套爱好字段的复合查询?

OpenSearch 1.3 查询实现方案

针对你需要实现的SQL查询逻辑,结合文档中hobbiles为嵌套类型的结构,可以使用以下OpenSearch DSL查询语句:

{
  "query": {
    "bool": {
      "must": [
        {
          "terms": {
            "_id": ["test@domain.com", "test1@domain.com"]
          }
        },
        {
          "range": {
            "age": {
              "gt": 5
            }
          }
        },
        {
          "nested": {
            "path": "hobbiles",
            "query": {
              "bool": {
                "should": [
                  { "match": { "hobbiles": "Chess" } },
                  { "match": { "hobbiles": "Dancing" } }
                ],
                "minimum_should_match": 1
              }
            }
          }
        }
      ]
    }
  }
}

各部分对应SQL条件说明:

  • terms 语句对应SQL中的 _id IN ('val1', 'val2'),指定要匹配的文档ID列表
  • range 语句对应 age > 5,筛选年龄大于5的文档
  • nested 查询用于处理嵌套类型字段hobbiles,内部的should子句实现匹配"Chess"或"Dancing"的逻辑,minimum_should_match:1确保至少满足其中一个条件

内容的提问来源于stack exchange,提问作者Pradip

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.20 18:03:28