java - Elasticsearch 查询中出现无效号码异常

标签 java elasticsearch

我正在执行此查询:

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

我只想根据日期范围聚合 Activity ,然后按 Activity 类型对这些范围进行子聚合,但 Elasticsearch 给了我这个异常(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
}

有什么想法我错过了什么吗?

最佳答案

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

关于java - Elasticsearch 查询中出现无效号码异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45176537/

相关文章:

java - 将对象添加到数组

java - 当 Jmeter.bat 中的堆大小增加时无法打开 Jmeter?

java - 如何在java中显示50位或更多(例如乘法)?

c# - 列表项上的ElasticSearch聚合

java - 将字符串中的整数提取到数组中

spring-boot - Spring Data Elasticsearch 自定义@Query 超过10个参数

php - elasticsearch根据位置查找文档

elasticsearch - “empty” elasticsearch incompatible-snapshots文件是否正常?

elasticsearch - 在文本字段上进行 Elasticsearch 关键字搜索不会返回结果

java - Java 中的 Setters 与重载构造函数