[英]Elastic query to search a term and with in a date range
GET _search
{
"query": {
"bool":{
"filter":{
"and":[
{
"term":{
"Server": "XYZ"
},
"range": {
"DateTime":{
"from": "2018-12-13T00:20:48.782Z",
"to":"2018-12-14T00:20:48.782Z"
}
}
}
]
}}
}
}
以上是我的彈性查詢,用於獲取屬於XYZ
服務器的所有記錄,並且在時間范圍內,我的數據集中有Server
和DateTime
列,但拋出以下錯誤:
{ "error": { "root_cause": [ { "type": "parsing_exception", "reason": "[term] 格式錯誤的查詢,預期為 [END_OBJECT] 但發現 [FIELD_NAME]", "line": 9, "col ": 11 } ], "type": "parsing_exception", "reason": "[term] 格式錯誤的查詢,預期為 [END_OBJECT] 但發現 [FIELD_NAME]", "line": 9, "col": 11 }, "狀態”:400 }
我在這里錯過了什么!
您的查詢格式錯誤,請改用以下查詢:
GET _search
{
"query": {
"bool": {
"filter": [
{
"term": {
"Server": "XYZ"
}
},
{
"range": {
"DateTime":{
"from": "2018-12-13T00:20:48.782Z",
"to": "2018-12-14T00:20:48.782Z"
}
}
}
]
}
}
}
您不能在過濾器子句中使用and
。 ES 查詢中沒有and
子句。 基本上,您需要在term
和range
子句上組合過濾器。 請閱讀ES 中的組合過濾器以獲取更多信息。
由於您的查詢使用了無效子句,ES 無法解析您的查詢。
請使用正確的查詢,您應該能夠從 ES 獲得結果。
請嘗試下面的查詢,它應該可以正常工作,如果它不起作用,請告訴我。
{
"query": {
"constant_score": {
"filter": {
"bool": {
"must": [
{
"term": {
"Server": "XYZ"
}
},
{
"bool": {
"must": [
{
"range": {
"DateTime": {
"from": "2018-12-13T00:20:48.782Z",
"to": "2018-12-14T00:20:48.782Z"
}
}
}
]
}
}
]
}
}
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.