无法从elasticsearch中的搜索文本中删除双引号(“)?

时间:2017-01-19 06:01:34

标签: c# elasticsearch

我正在进行弹性搜索查询,如下所示:

{
    "query_string": {
    "query": "*metallic ladder 80\"W",
    "default_operator": "or",
    "fields": [
         "attributes.attributevalues"
            ]
        }
    }

这里我试图从搜索文本中删除双引号。

为此,我收到“无法解析查询[* metallic ladder 80”*]“

我在我的应用程序中搜索此产品但由于此错误,我没有得到任何结果。

如果有人建议我们在使用elasticsearch时可以在searchterm中包含双引号,那将是一个很大的帮助。

完整错误如下:

    {
     "error": {
    "root_cause": [
      {
    "type": "query_parsing_exception",
    "reason": "Failed to parse query [*metallic ladder 80"*]",
    "index": "finefoodindex"
    }
    ],
    "type": "search_phase_execution_exception",
    "reason": "all shards failed",
    "phase": "query",
    "grouped": true,
    "failed_shards": [
      {
    "shard": 0,
    "index": "finefoodindex",
    "node": "aVgE3oxST3KcP3I--b-pIQ",
    "reason": {
    "type": "query_parsing_exception",
    "reason": "Failed to parse query [*metallic ladder 80"*]",
    "index": "finefoodindex",
    "caused_by": {
    "type": "parse_exception",
    "reason": "Cannot parse '*metallic ladder 80"*': Lexical error at line                 1, column 22. Encountered: <EOF> after : "\"*"",
    "caused_by": {
    "type": "token_mgr_error",
    "reason": "Lexical error at line 1, column 22. Encountered: <EOF> after                 : "\"*""
    }
    }
    }
    }
    ],
    },
    "status": 400
    }

2 个答案:

答案 0 :(得分:1)

如上面的评论所述,您还需要转义反斜杠字符,如下所示:

{
    "query_string": {
    "query": "*metallic ladder 80\\"W",
    "default_operator": "or",
    "fields": [
         "attributes.attributevalues"
            ]
        }
    }

答案 1 :(得分:0)

这对我有用。

{
    "query_string": {
        "query": "*metallic ladder 80\\\"W*",
        "default_operator": "or",
        "fields": [
            "attributes.attributevalues"
        ]
    }
}