我们是否需要在 Solr 搜索的搜索值中包含斜杠 (/) 的转义字符



我们是否需要在 Solr 搜索的搜索值中包含斜杠 (/) 的转义字符

q=*:*&indent=on&wt=json&rows=0&json.facet={"log_timestamp":{"type":"query","numBuckets":false,"facet":{"log_timestamp":{"type":"terms","field":"log_timestamp","limit":5,"mincount":1,"sort":{"count":"desc"},"numBuckets":true}},"q":"log_timestamp:/.*[AA][/][Cc].*/"},"destination_code_desc":{"type":"query","numBuckets":false,"facet":{"destination_code_desc":{"type":"terms","field":"destination_code_desc","limit":5,"mincount":1,"sort":{"count":"desc"},"numBuckets":true}},"q":"destination_code_desc:/.*[AA][/][Cc].*/"}}&fq=record_type:TEST&fq=log_timestamp:[1201-12-04T05:50:35Z+TO+2017-01-01T06:00:00Z]

这是我看到的错误

"error":{
    "metadata":[
      "error-class","org.apache.solr.common.SolrException",
      "root-error-class","org.apache.solr.parser.TokenMgrError"],
    "msg":"org.apache.solr.search.SyntaxError: Cannot parse 'log_timestamp:/.*[AA][/][Cc].*/': Lexical error at line 1, column 24.  Encountered: "]" (93), after : """,
    "code":400}}

您必须对其进行转义 - 您的问题是您使用正则表达式进行搜索,并且由于您使用/作为表达式的分隔符,因此表达式中的/会结束表达式。

您可以通过将放在角色前面来转义角色 - 但如果它本身不起作用,您可能需要转义两次,从而有效地放入\/。尝试两者。

最新更新