2013-04-16 53 views
4

我使用elasticsearch搜索引擎,当我运行下面的代码,返回的结果不符合标准的范围内(我得到低于期望的极限公布日期的项目):范围过滤器不工作

#!/bin/bash 
curl -X GET 'http://localhost:9200/newsidx/news/_search?pretty' -d '{ 

    "fields": [ 
     "art_text", 
     "title", 
     "published", 
     "category" 
    ], 
    "query": { 
     "bool": { 

      "should": [ 
       { 
        "fuzzy": {"art_text": {"boost": 89, "value": "google" }} 
       }, 
       { 
        "fuzzy": {"art_text": {"boost": 75, "value": "twitter" }} 
       } 
      ], 
      "minimum_number_should_match": 1 
     } 
    }, 
    "filter" : { 
     "range" : { 
      "published" : { 
       "from" : "2013-04-12 00:00:00" 
      } 
     } 
    } 

} 

' 

我也尝试把范围子句放在一个必须的,在布尔查询中,但结果是一样的。

编辑:我使用elasticsearch通过河流插件在mongodb中搜索。这是我用ES搜索mongodb db的脚本:

#!/bin/bash 
curl -X PUT localhost:9200/_river/mongodb/_meta -d '{ 
     "type":"mongodb", 
     "mongodb": { 
       "db": "newsful", 
       "collection": "news" 
     }, 
    "index": { 
      "name": "newsidx", 
     "type": "news" 
    } 
}' 

除此之外,我没有创建其他索引。

编辑2:

视图到ES映射:

http://localhost:9200/newsidx/news/_mapping 

published: { 
    type: "string" 
} 
+1

是您的'发布'字段索引为日期?你可以发布你目前的地图吗? – javanna

+0

我编辑帖子为了回答你的问题。 – Rod0n

回答

2

原因是在映射。您用作日期的已发布字段将被索引为一个字符串。这可能是因为您使用的date format不是elasticsearch中的默认设置,因此字段类型不会自动检测到,并且它被编入索引为简单字符串。

您应该使用put mapping api更改您的映射。您需要将发布的字段定义为日期,指定您使用的格式(可以是多个)并重新索引数据。

之后,你的范围过滤器应该工作!