在 ES 1.5 中,keep_types token filter 显然是为这类事情而设计的。我在这段代码中设置了它(使用 ES 1.5),它似乎工作:
http://sense.qbox.io/gist/b2c86b748d0c33957df1dcb90a3b405b0a4ca646
但是,我实际上并不需要它来让它工作。 standard analyzer 将文本划分为基于空格的标记,因此您可以对字段应用 range 查询(过滤器也可以),它似乎可以满足您的需求:
我设置了一个简单的索引:
DELETE /test_index
PUT /test_index
POST /test_index/doc/_bulk
{ "index": { "_id": 1 }}
{ "msg": "I have 7 books" }
{ "index": { "_id": 2 }}
{ "msg": "I have 15 books" }
{ "index": { "_id": 3 }}
{ "msg": "I have 19 books" }
然后使用范围查询:
POST /test_index/_search
{
"query": {
"range": {
"msg": {
"from": 10,
"to": 20
}
}
}
}
...
{
"took": 3,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 2,
"max_score": 1,
"hits": [
{
"_index": "test_index",
"_type": "doc",
"_id": "2",
"_score": 1,
"_source": {
"msg": "I have 15 books"
}
},
{
"_index": "test_index",
"_type": "doc",
"_id": "3",
"_score": 1,
"_source": {
"msg": "I have 19 books"
}
}
]
}
}
这是第二个例子的代码:
http://sense.qbox.io/gist/0979803673efb5b7ff063c257efd82617a93bd06