【问题标题】:Elasticsearch range query on list of object对象列表上的 Elasticsearch 范围查询
【发布时间】:2017-07-31 17:38:56
【问题描述】:

这是我的地图

{             "seoSubscribedFlag": {"type": "boolean"},
            "seoSubscribedExpiryDate": {"type": "date"},
            "userActive" :{"type" : "boolean"},
            "emailVerified" :{"type" : "boolean"},
            "isOnLineShodAdded" :{"type" : "boolean"},
            "productList" : {
                "properties" : {
                    "prodId" : {"type" : "string"},
                    "prodName" : {"type" : "string"},
                    "brand" : {"type" : "string"},
                    "modelNo" : {"type" : "string"},

                    "grossAmt" : {"type" : "float"},
                    "netAmt" : {"type" : "float"},
                    "prodDesc" : {"type" : "string"},
                    "prodKeyFeatures" : {"type" : "string"},
                    "prodSize" :{ "type": "nested" }

                }
            }
        }

这是我的乔恩

{
"userId": "2",  
"seoSubscribedFlag": true,
"seoSubscribedExpiryDate": 1501312549,
"userActive" : true,
"emailVerified" : true,
"isOnLineShodAdded" : false,
"productList" : {
    "properties" : {
        "prodId" : "2",            
        "netAmt" : 50,            
        "prodSize" :["XS","XL"]

    }
}
}

我想根据产品 netAmt 使用 BOOL MUST 搜索数据, 像 netAmt 必须在 10 到 60 之间 我尝试 BOOL MUST RANGE 但它不适用于对象列表

【问题讨论】:

    标签: elasticsearch filter range-query


    【解决方案1】:
    {
      "query": {
        "bool": {
          "must": {
            "range": {
              "productList.netAmt": {
                "gt": 10,
                "lt": 60
              }
            }
          }
        }
      }
    }
    

    请参考ESrange query

    【讨论】:

    • 您好,但布尔必须范围不适用于对象列表
    • @Amar Gohil 它应该可以工作。你能提供你的映射吗?
    • @Zhitoa Yue 在这里.... "isOnLineShodAdded" :{"type" : "boolean"}, "productList" : { "properties" : { "grossAmt" : {"type" : "float"}, "netAmt" : {"type" : "float"}, "prodSize" :{ "type": "nested" } } }
    • 我刚看到你的样例数据是这样的"productList" : { "properties" : { "prodId" : "2", "netAmt" : 50, "prodSize" :["XS","XL"] } } 能不能改成"productList" : { "prodId" : "2", "netAmt" : 50, "prodSize" :["XS","XL"] } 放数据的时候不需要加properties
    • 我无法添加没有属性的数据给我错误,例如 [productList.prodSize] 的对象映射试图将字段 [null] 解析为对象,但找到了具体值
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多