Solr – "Error adding field … msg=Invalid Date String" when sending json data to core

huangapple go评论99阅读模式
英文:

Solr - "Error adding field … msg=Invalid Date String" when sending json data to core

问题

  1. 我对Solr还不熟悉。<br>
  2. 我正在尝试将日志文件传递给Solr。为此,我使用日志文件 -&gt; Filebeat -&gt; Logstash -&gt; Solr
  3. <br>
  4. <br>
  5. **问题**
  6. Logstash的输出是正常的,但是Solr保持为空。<br>
  7. 因为Logstash输出的文本是"2020-01-01 00:00:00.000",我尝试使用cURL执行Solr更新,例如以下命令。
  8. <br>
  9. <br>
  10. 第一个命令:(字段"my_datetime"的尾部是Z
  11. curl -X POST -d '{ "add":{ "doc":{ "my_datetime":"2020-01-01T00:00:00.000Z" }}}' -H "Content-Type: application/json" http://localhost:8983/solr/Collection/update?commit=true
  12. 第二个命令:(字段"my_datetime"的尾部不是Z
  13. curl -X POST -d '{ "add":{ "doc":{ "my_datetime":"2020-01-01 00:00:00.000" }}}' -H "Content-Type: application/json" http://localhost:8983/solr/Collection/update?commit=true
  14. <br>
  15. **问题**
  16. 第一个命令可以正常工作。
  17. 但是第二个命令无法工作,我收到了异常:
  18. {
  19. "responseHeader":{
  20. "status":400,
  21. "QTime":13},
  22. "error":{
  23. "metadata":[
  24. "error-class","org.apache.solr.common.SolrException",
  25. "root-error-class","org.apache.solr.common.SolrException"],
  26. "msg":"ERROR: [doc=60146d1c-ed31-4dda-b90e-e93537b8a63a] Error adding field 'my_datetime'='2020-01-01 00:00:00.000' msg=Invalid Date String:'2020-01-01 00:00:00.000'",
  27. "code":400}}
  28. <br>
  29. **环境**
  30. - Solr v8.3.0上测试过
  31. 这是我的managed-schema
  32. <fieldType name="pdates" class="solr.DatePointField" docValues="true" multiValued="true"/>
  33. <field name="my_datetime" type="pdate" indexed="true" stored="true"/>
  34. 这是我的solrconfig.xml
  35. <updateProcessor class="solr.ParseDateFieldUpdateProcessorFactory" name="parse-date">
  36. <arr name="format">
  37. <str>yyyy-MM-dd'T'HH:mm:ss.SSSZ</str>
  38. <str>yyyy-MM-dd'T'HH:mm:ss,SSS[Z</str>
  39. <str>yyyy-MM-dd'T'HH:mm:ss.SSS</str>
  40. ...
  41. (其他格式)
  42. ...
  43. <str>[EEE, ]dd MMM yyyy HH:mm[:ss] z</str>
  44. <str>EEEE, dd-MMM-yy HH:mm:ss z</str>
  45. <str>EEE MMM ppd HH:mm:ss [z ]yyyy</str>
  46. </arr>
  47. </updateProcessor>
  48. <updateRequestProcessorChain name="add-unknown-fields-to-the-schema" default="${update.autoCreateFields:true}"
  49. processor="uuid,remove-blank,field-name-mutating,parse-boolean,parse-long,parse-double,parse-date,add-schema-fields">
  50. <processor class="solr.LogUpdateProcessorFactory"/>
  51. <processor class="solr.DistributedUpdateProcessorFactory"/>
  52. <processor class="solr.RunUpdateProcessorFactory"/>
  53. </updateRequestProcessorChain>
  54. 谢谢您的帮助!
英文:

I am new to Solr.<br>
I am trying to pass log files to Solr. For that I use log file -> Filebeat -> Logstash -> Solr.

<br>
<br>

PROBLEM

Logstash output is fine, but Solr remain empty.<br>
Because Logstash output text is "2020-01-01 00:00:00.000", I have tried to use cURL to perform Solr updates, such as the following commands.
<br>
<br>
First Command: ( the trailing of field "my_datetime" is Z)

  1. curl -X POST -d &#39;{&quot;add&quot;:{ &quot;doc&quot;:{&quot;my_datetime&quot;:&quot;2020-01-01T00:00:00.000Z&quot;}}}&#39; -H &quot;Content-Type: application/json&quot; http://localhost:8983/solr/Collection/update?commit=true

Second Command: ( the trailing of field "my_datetime" is not Z)

  1. curl -X POST -d &#39;{&quot;add&quot;:{ &quot;doc&quot;:{&quot;my_datetime&quot;:&quot;2020-01-01 00:00:00.000&quot;}}}&#39; -H &quot;Content-Type: application/json&quot; http://localhost:8983/solr/Collection/update?commit=true

<br>

QUESTION

First command does work.
But second command does not work, I have received an exception:

  1. {
  2. &quot;responseHeader&quot;:{
  3. &quot;status&quot;:400,
  4. &quot;QTime&quot;:13},
  5. &quot;error&quot;:{
  6. &quot;metadata&quot;:[
  7. &quot;error-class&quot;,&quot;org.apache.solr.common.SolrException&quot;,
  8. &quot;root-error-class&quot;,&quot;org.apache.solr.common.SolrException&quot;],
  9. &quot;msg&quot;:&quot;ERROR: [doc=60146d1c-ed31-4dda-b90e-e93537b8a63a] Error adding field &#39;my_datetime&#39;=&#39;2020-01-01 00:00:00.000&#39; msg=Invalid Date String:&#39;2020-01-01 00:00:00.000&#39;&quot;,
  10. &quot;code&quot;:400}}

<br>

ENVIRONMENT

  • Tested on Solr v8.3.0

This is my managed-schema

  1. &lt;fieldType name=&quot;pdates&quot; class=&quot;solr.DatePointField&quot; docValues=&quot;true&quot; multiValued=&quot;true&quot;/&gt;
  2. &lt;field name=&quot;my_datetime&quot; type=&quot;pdate&quot; indexed=&quot;true&quot; stored=&quot;true&quot;/&gt;

This is my solrconfig.xml

  1. &lt;updateProcessor class=&quot;solr.ParseDateFieldUpdateProcessorFactory&quot; name=&quot;parse-date&quot;&gt;
  2. &lt;arr name=&quot;format&quot;&gt;
  3. &lt;str&gt;yyyy-MM-dd&#39;T&#39;HH:mm:ss.SSSZ&lt;/str&gt;
  4. &lt;str&gt;yyyy-MM-dd&#39;T&#39;HH:mm:ss,SSS[Z&lt;/str&gt;
  5. &lt;str&gt;yyyy-MM-dd&#39;T&#39;HH:mm:ss.SSS&lt;/str&gt;
  6. &lt;str&gt;yyyy-MM-dd&#39; &#39;HH:mm:ss.SSS&lt;/str&gt;
  7. &lt;str&gt;yyyy-MM-dd&#39;T&#39;HH:mm:ssZ&lt;/str&gt;
  8. &lt;str&gt;yyyy-MM-dd&#39;T&#39;HH:mm:ss&lt;/str&gt;
  9. &lt;str&gt;yyyy-MM-dd&#39;T&#39;HH:mmZ&lt;/str&gt;
  10. &lt;str&gt;yyyy-MM-dd&#39;T&#39;HH:mm&lt;/str&gt;
  11. &lt;str&gt;yyyy-MM-dd HH:mm:ss.SSSZ&lt;/str&gt;
  12. &lt;str&gt;yyyy-MM-dd HH:mm:ss,SSSZ&lt;/str&gt;
  13. &lt;str&gt;yyyy-MM-dd HH:mm:ss.SSS&lt;/str&gt;
  14. &lt;str&gt;yyyy-MM-dd HH:mm:ss,SSS&lt;/str&gt;
  15. &lt;str&gt;yyyy-MM-dd HH:mm:ssZ&lt;/str&gt;
  16. &lt;str&gt;yyyy-MM-dd HH:mm:ss&lt;/str&gt;
  17. &lt;str&gt;yyyy-MM-dd HH:mmZ&lt;/str&gt;
  18. &lt;str&gt;yyyy-MM-dd HH:mm&lt;/str&gt;
  19. &lt;str&gt;yyyy-MM-dd&lt;/str&gt;
  20. &lt;str&gt;yyyy-MM-dd[&#39;T&#39;[HH:mm[:ss[.SSS]]&lt;/str&gt;
  21. &lt;str&gt;yyyy-MM-dd[&#39;T&#39;[HH:mm[:ss[.SSS]][z&lt;/str&gt;
  22. &lt;str&gt;yyyy-MM-dd[&#39;T&#39;[HH:mm[:ss[.SSS]][z&lt;/str&gt;
  23. &lt;str&gt;yyyy-MM-dd[&#39;T&#39;[HH:mm[:ss[,SSS]][z&lt;/str&gt;
  24. &lt;str&gt;yyyy-MM-dd HH:mm[:ss[.SSS]][z&lt;/str&gt;
  25. &lt;str&gt;yyyy-MM-dd HH:mm[:ss[.SSS]]&lt;/str&gt;
  26. &lt;str&gt;yyyy-MM-dd HH:mm[:ss[,SSS]][z&lt;/str&gt;
  27. &lt;str&gt;[EEE, ]dd MMM yyyy HH:mm[:ss] z&lt;/str&gt;
  28. &lt;str&gt;EEEE, dd-MMM-yy HH:mm:ss z&lt;/str&gt;
  29. &lt;str&gt;EEE MMM ppd HH:mm:ss [z ]yyyy&lt;/str&gt;
  30. &lt;/arr&gt;
  31. &lt;/updateProcessor&gt;
  32. &lt;updateRequestProcessorChain name=&quot;add-unknown-fields-to-the-schema&quot; default=&quot;${update.autoCreateFields:true}&quot;
  33. processor=&quot;uuid,remove-blank,field-name-mutating,parse-boolean,parse-long,parse-double,parse-date,add-schema-fields&quot;&gt;
  34. &lt;processor class=&quot;solr.LogUpdateProcessorFactory&quot;/&gt;
  35. &lt;processor class=&quot;solr.DistributedUpdateProcessorFactory&quot;/&gt;
  36. &lt;processor class=&quot;solr.RunUpdateProcessorFactory&quot;/&gt;
  37. &lt;/updateRequestProcessorChain&gt;

Thanks for you help!

答案1

得分: 2

你应该以正确的格式传递日期值。

当日期时间字符串的格式无效时,SOLR会抛出错误。SOLR只允许使用 YYYY-MM-DDThh:mm:ssZ 格式的日期时间字符串。

正确的格式是 2020-10-01T00:00:00Z。在你分享的示例中也起作用了。

在你的logstash文件中添加适当的过滤器,将日期转换为上述期望的格式。

英文:

You should pass the date value in correct format.

The error is thrown by SOLR when a datetime string have an invalid format. SOLR only allows datetime strings in the format of YYYY-MM-DDThh:mm:ssZ.

The correct format is 2020-10-01T00:00:00Z. It also worked in the example shared by you.

Add appropriate filter in your logstash file to mutate the date in the above expected format.

huangapple
  • 本文由 发表于 2020年10月8日 13:46:10
  • 转载请务必保留本文链接:https://go.coder-hub.com/64256484.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定