2015-04-03 446 views
0

有没有什么方法可以在使用过滤器查询时转换字段的数据类型。 ,我不得不的场景是我有一个文件与现场Elasticsearch在查询时转换字段的数据类型

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 
} 

在上述字段中的值属性可以是任何数据类型(字符串,DATATIME,或数字),在那里,因为我需要使用来提取数据的范围过滤器(大于,小于)。这个范围过滤器应具有长期滤波器结合使用我布尔过滤器做了一个查询作为

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

}

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

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

回答

0

也许查询格式不正确。我使用这个:

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

没有变化,带来了所有的记录。这个问题与'customData.value'的归档类型相关吗? – 2015-04-03 08:29:02

+0

我不知道对不起。也许你可以在创建索引之前尝试对数据进行映射。 映射允许您为每个字段选择一种类型(并且格式类似大写/小写/分析数据等) – AlainIb 2015-04-03 11:54:52