5

我正在使用 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"
            }
        }
    }

}

'

我还尝试将 range 子句放在 bool 查询中的一个必须项中,但结果是相同的。

编辑:我使用 elasticsearch 通过河插件在 mongodb 中搜索。这是我运行以使用 ES 搜索 mongodb 数据库的脚本:

#!/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"
}
4

1 回答 1

2

The reason is in your mapping. The published field, which you are using as a date, is indexed as a string. That's probably because the date format you are using is not the default one in elasticsearch, thus the field type is not auto-detected and it's indexed as a simple string.

You should change your mapping using the put mapping api. You need to define the published field as a date there, specifying the format you're using (can be more than one) and reindex your data.

After that your range filter should work!

于 2013-04-16T17:20:20.673 回答