在我eleasticsearch指数,我有两个文件索引,如下过滤器一起:期限和范围内,在elasticsearch查询
POST dyn-props/item
{
"name": "bar foo",
"properties": [
{
"type": "foo",
"value": 1.45
},
{
"type": "bar",
"value": 256.34
},
{
"type": "foobar",
"value": 43.43
}
]
}
POST dyn-props/item
{
"name": "foo bar",
"properties": [
{
"type": "foo",
"value": 33.34
},
{
"type": "bar",
"value": 22.23
}
]
}
在此项目类型,我想查询具有富物业项目其价值大于。我可以筛选结果下来有一个类型为FOO与下面的查询属性的项目:
POST dyn-props/item/_search
{
"query": {
"filtered": {
"query": {
"match_all": {}
},
"filter": {
"term": {
"properties.type": "foo"
}
}
}
}
}
,但我不知道我怎么能应用范围过滤器值。任何想法?
编辑:
发出下面的查询给了我预期的错误的结果:
POST dyn-props/item/_search
{
"query": {
"filtered": {
"query": {
"match_all": {}
},
"filter": {
"bool": {
"must": [
{
"term": {
"properties.type": "foo"
}
},
{
"range": {
"properties.value": {
"gte" : 10
}
}
}
]
}
}
}
}
}
结果:
{
"took": 2,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 2,
"max_score": 1,
"hits": [
{
"_index": "dyn-props",
"_type": "item",
"_id": "PetPVxwARLOcZqlv28xjpw",
"_score": 1,
"_source": {
"name": "bar foo",
"properties": [
{
"type": "foo",
"value": 1.45
},
{
"type": "bar",
"value": 256.34
},
{
"type": "foobar",
"value": 43.43
}
]
}
},
{
"_index": "dyn-props",
"_type": "item",
"_id": "KqOTXcC9RG6FzPsDDDs8Hw",
"_score": 1,
"_source": {
"name": "foo bar",
"properties": [
{
"type": "foo",
"value": 33.34
},
{
"type": "bar",
"value": 22.23
}
]
}
}
]
}
}
试试这个http://www.elasticsearch.org/guide/en/elasticsearch/reference/0.90/query-dsl-numeric-range-filter。 html – 2014-09-21 13:14:06
@Undefined_variable不确定你的意思。我知道我需要使用范围过滤器。问题在于如何。 – tugberk 2014-09-21 13:17:25
使用和过滤器的细节可以在http://www.elasticsearch.org/guide/en/elasticsearch/reference/0.90/query-dsl-and-filter.html – 2014-09-21 13:25:39