简体   繁体   English

在弹性搜索查询中获取无效的数字异常

[英]Getting Invalid Number Exception on elastic search query

I am executing this query : 我正在执行此查询:

{
  "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"
          }
        }
      }
    }
  }
}

Where I just want to aggregation activity based on date ranges and then sub aggregate those ranges by activity type but Elastic search is giving me this exception : 我只想根据日期范围聚合活动,然后按活动类型对这些范围进行子聚合,但是弹性搜索给我这个异常:

{
    "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
}

Any Ideas what am I missing? 任何想法我想念什么?

The format parameter is to specify in which format the dates should be returned in the response, not in which format they are specified in the request. format参数用于指定响应中应以哪种格式返回日期,而不是在请求中以哪种格式指定日期。 So depending on the date format of the timestamp field you have specified in your mapping type, your request needs to contain full-fledge dates, like this: 因此,根据您在映射类型中指定的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"
      }
    }
  }
},

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM