【发布时间】:2020-11-13 16:20:43
【问题描述】:
我有一个关于将过滤器键传递给脚本语言的问题。
基本上,我已将过滤器定义如下,在我的脚本查询中,我想使用过滤器键月份作为 DOM 平均计算的一部分。在我的示例中,我硬编码了一个日期值,但它应该是过滤器定义的键值。如果您能就如何解决这个问题给我一些反馈,我们将不胜感激。
这是完整的查询:
GET offmarketlistings,listings,soldlistings/_search
{
"size": 0,
"query": {
"bool": {
"must": [
{
"term": {
"isRental": {
"value": false
}
}
},
{
"terms": {
"zip": [
"20852",
"20001",
"20878"
]
}
},
{
"range": {
"sqft": {
"gte": 1500.0,
"lte": 3500.0
}
}
},
{
"range": {
"bed": {
"gte": 1.0,
"lte": 7.0
}
}
}
]
}
},
"aggs": {
"zip_bucket": {
"terms": {
"field": "zip"
},
"aggs": {
"active_monthly_bucket": {
"filters": {
"filters": {
"7/1/2020": {
"bool": {
"must": [
{
"range": {
"listDate": {
"lt": "2020/08/01",
"format": "yyyy/MM/dd"
}
}
},
{
"bool": {
"should": [
{
"bool": {
"must_not": [
{
"exists": {
"field": "soldDate"
}
}
]
}
},
{
"bool": {
"must": [
{
"exists": {
"field": "soldDate"
}
},
{
"range": {
"soldDate": {
"gt": "2020/07/01",
"format": "yyyy/MM/dd"
}
}
}
]
}
}
]
}
},
{
"bool": {
"should": [
{
"bool": {
"must_not": [
{
"exists": {
"field": "offMarketDate"
}
}
]
}
},
{
"bool": {
"must": [
{
"exists": {
"field": "offMarketDate"
}
},
{
"range": {
"offMarketDate": {
"gt": "2020/07/01",
"format": "yyyy/MM/dd"
}
}
}
]
}
}
]
}
}
]
}
},
"9/1/2019": {
"bool": {
"must": [
{
"range": {
"listDate": {
"lt": "2019/10/01",
"format": "yyyy/MM/dd"
}
}
},
{
"bool": {
"should": [
{
"bool": {
"must_not": [
{
"exists": {
"field": "soldDate"
}
}
]
}
},
{
"bool": {
"must": [
{
"exists": {
"field": "soldDate"
}
},
{
"range": {
"soldDate": {
"gt": "2019/09/01",
"format": "yyyy/MM/dd"
}
}
}
]
}
}
]
}
},
{
"bool": {
"should": [
{
"bool": {
"must_not": [
{
"exists": {
"field": "offMarketDate"
}
}
]
}
},
{
"bool": {
"must": [
{
"exists": {
"field": "offMarketDate"
}
},
{
"range": {
"offMarketDate": {
"gt": "2019/09/01",
"format": "yyyy/MM/dd"
}
}
}
]
}
}
]
}
}
]
}
},
"8/1/2019": {
"bool": {
"must": [
{
"range": {
"listDate": {
"lt": "2019/09/01",
"format": "yyyy/MM/dd"
}
}
},
{
"bool": {
"should": [
{
"bool": {
"must_not": [
{
"exists": {
"field": "soldDate"
}
}
]
}
},
{
"bool": {
"must": [
{
"exists": {
"field": "soldDate"
}
},
{
"range": {
"soldDate": {
"gt": "2019/08/01",
"format": "yyyy/MM/dd"
}
}
}
]
}
}
]
}
},
{
"bool": {
"should": [
{
"bool": {
"must_not": [
{
"exists": {
"field": "offMarketDate"
}
}
]
}
},
{
"bool": {
"must": [
{
"exists": {
"field": "offMarketDate"
}
},
{
"range": {
"offMarketDate": {
"gt": "2019/08/01",
"format": "yyyy/MM/dd"
}
}
}
]
}
}
]
}
}
]
}
}
}
},
"aggs": {
"listPrice_Stats": {
"stats": {
"field": "listPrice"
}
},
"listPrice_median": {
"percentiles": {
"field": "listPrice",
"percents": [
50.0
]
}
},
"dom_stats": {
"stats": {
"script": {
"inline": "ChronoUnit.DAYS.between(ZonedDateTime.ofInstant(Instant.ofEpochMilli(doc['listDate'].value), ZoneId.of('Z')), ZonedDateTime.parse('2020-07-22T16:45:08Z'))"
}
}
}
}
}
}
}
}
}
【问题讨论】:
-
在您的屏幕截图中包含代码是一种很好的做法,而不仅仅是屏幕截图。
-
我已附上完整的查询。
标签: elasticsearch kibana elasticsearch-dsl