[英]How to compare two date fields in same document in elasticsearch
[英]How to compare two fields in the same document in ElasticSearch?
我正在使用ElasticSearch 7.2.0,
我在具有三個字段的索引中有文檔id, field1, field2
我想查詢並返回其field1 > 20
AND field1 > field2
那些文檔
以下是我正在嘗試的查詢-
GET /test/_search
{
"query": {
"function_score": {
"query": {
"constant_score": {
"filter": {
"bool": {
"must": [
{
"range" : {
"field1" : {
"gte" : 20
}
}
},
{
"script": {
"source": "doc['field1'].value > doc['field2'].value",
"params": {
}
}}
]
}
}
}
}
}
}
}
以下是錯誤-
{
"error": {
"root_cause": [
{
"type": "parsing_exception",
"reason": "[script] query does not support [source]",
"line": 18,
"col": 29
}
],
"type": "parsing_exception",
"reason": "[script] query does not support [source]",
"line": 18,
"col": 29
},
"status": 400
}
您的查詢是正確的! 您只需要將script
包裝在另一個script
。 第一個是表示script
查詢,第二個是實際定義腳本:
{
"query": {
"function_score": {
"query": {
"constant_score": {
"filter": {
"bool": {
"must": [
{
"range": {
"field1": {
"gte": 20
}
}
},
{
"script": {
"script": {
"source": "doc['field1'].value > doc['field2'].value",
"params": {}
}
}
}
]
}
}
}
}
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.