elasticsearch 7数字\u格式\u字符串输入值异常

jdg4fx2g  于 2021-06-14  发布在  ElasticSearch
关注(0)|答案(1)|浏览(508)

索引中的字段Map为:

  1. "sequence_number" : {
  2. "type" : "long",
  3. "copy_to" : [
  4. "_custom_all"
  5. ]
  6. }

使用搜索查询作为

  1. POST /my_index/_search
  2. {
  3. "query": {
  4. "term": {
  5. "sequence_number": {
  6. "value": "we"
  7. }
  8. }
  9. }
  10. }

我收到错误消息:

  1. ,"index_uuid":"FTAW8qoYTPeTj-cbC5iTRw","index":"my_index","caused_by":{"type":"number_format_exception","reason":"For input string: \"we\""}}}]},"status":400}
  2. at org.elasticsearch.client.RestClient.convertResponse(RestClient.java:260) ~[elasticsearch-rest-client-7.1.1.jar:7.1.1]
  3. at org.elasticsearch.client.RestClient.performRequest(RestClient.java:238) ~[elasticsearch-rest-client-7.1.1.jar:7.1.1]
  4. at org.elasticsearch.client.RestClient.performRequest(RestClient.java:212) ~[elasticsearch-rest-client-7.1.1.jar:7.1.1]
  5. at org.elasticsearch.client.RestHighLevelClient.internalPerformRequest(RestHighLevelClient.java:1433) ~[elasticsearch-rest-high-level-client-7.1.1.jar:7.1.1]
  6. at

我怎么能忽略数字\格式\异常错误,这样查询就不会返回任何东西,或者忽略这个过滤器-任何一个都是可以接受的。
提前谢谢。

odopli94

odopli941#

您要查找的内容是不可能的,理想情况下,您应该在数字字段上启用cohere,以便索引不包含脏数据。
最好的解决方案是在生成elasticsearch查询的应用程序中(您应该检查 NumberFormatExcepton 如果您正在搜索数字字段,因为您的索引首先不包含脏数据(如果您的应用程序中出现异常,请拒绝查询)。
编辑:另一个有趣的方法是在插入es之前验证数据,使用@prakash建议的validate api,唯一的问题是它将添加另一个网络调用,但如果您的应用程序对延迟不敏感,则可以将其用作解决方法。

相关问题