2017-07-18 40 views
1

我執行這個查詢:獲得彈性的搜索查詢無效號碼特殊

{ 
    "query" : { 
    "match" : { 
     "studyID" : { 
     "query" : 1, 
     "type" : "boolean" 
     } 
    } 
    }, 
    "aggregations" : { 
    "25-34" : { 
     "date_range" : { 
     "field" : "timestamp", 
     "ranges" : [ { 
      "from" : "1992", 
      "to" : "1983" 
     } ], 
     "format" : "yyyy" 
     }, 
     "aggregations" : { 
     "activityType" : { 
      "terms" : { 
      "field" : "activityType" 
      } 
     } 
     } 
    }, 
    "84-*" : { 
     "date_range" : { 
     "field" : "timestamp", 
     "ranges" : [ { 
      "from" : "1933" 
     } ], 
     "format" : "yyyy" 
     }, 
     "aggregations" : { 
     "activityType" : { 
      "terms" : { 
      "field" : "activityType" 
      } 
     } 
     } 
    }, 
    "18-24" : { 
     "date_range" : { 
     "field" : "timestamp", 
     "ranges" : [ { 
      "from" : "1999", 
      "to" : "1993" 
     } ], 
     "format" : "yyyy" 
     }, 
     "aggregations" : { 
     "activityType" : { 
      "terms" : { 
      "field" : "activityType" 
      } 
     } 
     } 
    }, 
    "75-84" : { 
     "date_range" : { 
     "field" : "timestamp", 
     "ranges" : [ { 
      "from" : "1942", 
      "to" : "1933" 
     } ], 
     "format" : "yyyy" 
     }, 
     "aggregations" : { 
     "activityType" : { 
      "terms" : { 
      "field" : "activityType" 
      } 
     } 
     } 
    }, 
    "0-17" : { 
     "date_range" : { 
     "field" : "timestamp", 
     "ranges" : [ { 
      "from" : "2017", 
      "to" : "2000" 
     } ], 
     "format" : "yyyy" 
     }, 
     "aggregations" : { 
     "activityType" : { 
      "terms" : { 
      "field" : "activityType" 
      } 
     } 
     } 
    }, 
    "55-64" : { 
     "date_range" : { 
     "field" : "timestamp", 
     "ranges" : [ { 
      "from" : "1962", 
      "to" : "1953" 
     } ], 
     "format" : "yyyy" 
     }, 
     "aggregations" : { 
     "activityType" : { 
      "terms" : { 
      "field" : "activityType" 
      } 
     } 
     } 
    }, 
    "65-74" : { 
     "date_range" : { 
     "field" : "timestamp", 
     "ranges" : [ { 
      "from" : "1952", 
      "to" : "1943" 
     } ], 
     "format" : "yyyy" 
     }, 
     "aggregations" : { 
     "activityType" : { 
      "terms" : { 
      "field" : "activityType" 
      } 
     } 
     } 
    }, 
    "35-44" : { 
     "date_range" : { 
     "field" : "timestamp", 
     "ranges" : [ { 
      "from" : "1982", 
      "to" : "1973" 
     } ], 
     "format" : "yyyy" 
     }, 
     "aggregations" : { 
     "activityType" : { 
      "terms" : { 
      "field" : "activityType" 
      } 
     } 
     } 
    }, 
    "45-54" : { 
     "date_range" : { 
     "field" : "timestamp", 
     "ranges" : [ { 
      "from" : "1972", 
      "to" : "1963" 
     } ], 
     "format" : "yyyy" 
     }, 
     "aggregations" : { 
     "activityType" : { 
      "terms" : { 
      "field" : "activityType" 
      } 
     } 
     } 
    } 
    } 
} 

在那裏我只是想根據日期範圍,以聚集活性,然後子聚集按活動類型,但彈性搜索的範圍是給我這個例外:

{ 
    "error": { 
     "root_cause": [ 
      { 
       "type": "aggregation_execution_exception", 
       "reason": "Invalid number format [yyyy#]" 
      } 
     ], 
     "type": "search_phase_execution_exception", 
     "reason": "all shards failed", 
     "phase": "query", 
     "grouped": true, 
     "failed_shards": [ 
      { 
       "shard": 0, 
       "index": "study", 
       "node": "MWkXAAOCSYuM-ubdkulNnw", 
       "reason": { 
        "type": "aggregation_execution_exception", 
        "reason": "Invalid number format [yyyy#]" 
       } 
      } 
     ] 
    }, 
    "status": 500 
} 

任何想法我錯過了什麼?

回答

0

format參數用於指定日期應該在響應中返回的格式,而不是指定請求中指定的格式。因此,根據您在地圖類型中指定的timestamp字段的日期格式,您的請求需要包含完整日期,如下所示:

"25-34" : { 
    "date_range" : { 
    "field" : "timestamp", 
    "ranges" : [ { 
     "from" : "1992-01-01T00:00:00.000Z", 
     "to" : "1983-12-31T23:59.59.999Z" 
    } ], 
    "format" : "yyyy" 
    }, 
    "aggregations" : { 
    "activityType" : { 
     "terms" : { 
     "field" : "activityType" 
     } 
    } 
    } 
}, 
+0

這是什麼運氣? – Val