【问题标题】:Elasticsearch converting datatype of a field while queryingElasticsearch在查询时转换字段的数据类型
【发布时间】:2015-04-03 16:20:35
【问题描述】:

有什么方法可以在使用过滤器查询时转换字段的数据类型。 我的场景是我有一个带有字段的文档

customData: {
    "contactCustomFieldMapId":xxxx,
    "contactId":xxxxx,
    "customFieldId":45788,
    "value":"1899",
    "fieldInputTypeId":0
},
{
    "contactCustomFieldMapId":xxxx,
    "contactId":xxxxx,
    "customFieldId":45732,
    "value":"Meet me at noon",
    "fieldInputTypeId":0
},
{
    "contactCustomFieldMapId":xxxx,
    "contactId":xxxxx,
    "customFieldId":23233,
    "value":"233589",
    "fieldInputTypeId":0
}

在上述字段中,value 属性可以是任何数据类型(字符串、数据时间或数字),因为我需要使用范围过滤器(大于、小于)来获取数据。这个范围过滤器应该与一个术语过滤器结合使用我使用 bool 过滤器作为

"filter": {
"and": {
  "filters": [
    {
      "bool": {
        "must": [
          {
            "and": {
              "filters": [
                {
                  "term": {
                    "customData.customFieldId": 45788
                  }
                },
                {
                  "range": {
                    "customData.value": {
                      "gt": "1000"
                    }
                  }
                }
              ]
            }
          }
        ]
      }
    }
  ]
}

}

不幸的是,查询正在获取 customData.customFieldId 为 45788 的所有记录(与存在过滤器类似)。

有什么方法可以将术语过滤器和范围过滤器结合起来。

【问题讨论】:

    标签: elasticsearch sense


    【解决方案1】:

    可能查询格式不正确。我用这个:

     {
       "filtered": {
         "filter": {
           "and": [
             { "term": {
                      "customData.customFieldId": 45788
                  }
             },
             { "range": {
                     "customData.value": {
                           "gt": "1000"
                         }
                   }
             }
           ]
         }
       }
      }
    

    【讨论】:

    • 无变化,带来所有记录。这个问题是否与customData.value 的归档类型有关
    • 我不知道对不起。也许您可以尝试在创建索引之前对数据进行映射。映射可让您为每个字段选择一种类型(并使用大写/小写/等格式来分析数据等)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多