![](/img/trans.png)
[英]Elasticsearch: get all documents where array contains one of many values
[英]Filter documents where all values of an array meet some criteria in elasticsearch
我的文檔看起來像這樣:
{
times: [{start: "1461116454242"},{start:"1461116454242"}]
}
我希望獲得每個開始時間都在過去的所有文檔。 此查詢在所有時間都在將來或所有時間都在過去時有效,但如果將來只有一次(仍然匹配)則失敗。
query: { filtered: { filter: { bool: { must: [ { nested: { path: "times", filter: { script : { script: "doc['start'].value < now", params: { now: Date.now() } } } } } ] } }, query: { match_all: {} } } }
我剛剛意識到的一個解決方案:
query: { filtered: { filter: { bool: { must: [ { nested: { path: "times", filter: { "bool": { "must": [ { "range": { "times.start": { lt: new Date() } } } ] } } } } ], must_not: [ { nested: { path: "times", filter: { "bool": { "must": [ { "range": { "times.start": { gte: new Date() } } } ] } } } } ] } }, query: { match_all: {} } } }
這個怎么樣:
include_in_parent: true
映射中為include_in_parent: true
: "times": {
"type": "nested",
"include_in_parent": true,
"properties": {
"start": {
"type": "date"
}
}
}
query_string
語法,而不是nested
: {
"query": {
"query": {
"query_string": {
"query": "times.start:<=now AND NOT times.start:>now"
}
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.