我在弹性搜索中有一个奇怪的行为。我开始使用过滤器之前,我有一个查询: ElasticSearch过滤器对分类的影响
查询不带过滤器
{
"query": {
"bool": {
"must": [
{
"match": {
"_facility": {
"query": "error",
"operator": "AND"
}
}
},
{
"match": {
"_application": {
"query": "live",
"operator": "AND"
}
}
}
],
"must_not": [],
"should": []
}
},
"from": 0,
"size": 10,
"sort": [
{
"created_at": {
"sort_mode": null,
"order": "desc",
"missing": null,
"ignore_unmapped": null
}
},
{
"_score": {
"sort_mode": null,
"order": null,
"missing": null,
"ignore_unmapped": null
}
}
]
}
然后我不得不加滤网
{
"query": {
"bool": {
"must": [
{
"match": {
"_facility": {
"query": "error",
"operator": "AND"
}
}
},
{
"match": {
"_application": {
"query": "live",
"operator": "AND"
}
}
}
],
"must_not": [],
"should": []
}
},
"filter": {
"and": {
"filters": [
{
"range": {
"created_at": {
"from": 1373320800,
"to": 1373493599,
"include_lower": true,
"include_upper": true
},
"_cache": true
}
}
]
},
"_cache": false
},
"from": 0,
"size": 10,
"sort": [
{
"created_at": {
"sort_mode": null,
"order": "desc",
"missing": null,
"ignore_unmapped": null
}
},
{
"_score": {
"sort_mode": null,
"order": null,
"missing": null,
"ignore_unmapped": null
}
}
]
}
和我有未来的问题:
1 )结果没有正确地按照created_at排序,看起来像洗牌数据
2)大小 - 不考虑任何自定义值不同于10(假设我想显示20 [或5]记录,但我有10)
感谢您的帮助。可能我在弹性搜索概念中缺少一些东西。
您是否尝试使用FilteredQuery? http://www.elasticsearch.org/guide/reference/query-dsl/filtered-query/ – Damien
我试过了,但ElasticSearch抛出了一个解析错误。你能给我正确的json吗? –
感谢您的提示。问题出在'_cache'错误的位置,因为@imotov提到 –