如何添加和/或作为查询字符串的一部分?

时间:2019-05-15 11:40:24

标签: elasticsearch

我的某些关键字包含和/或。使用该数据时,我进行的字符串查询中断。我的字符串查询需要能够在其查询中处理该数据

这是我的查询和错误:

查询:

POST /test/_doc
{
  "keyword":"pizza oven and/or pizza"
}

GET /test/_search
{
  "query": {
    "bool": {
      "should": [
        {
          "query_string": {
            "default_field": "keywords.english",
            "query": "(pizza oven and/or pizza) OR (bread)"
          }
       }
      ]
    }
  }
}

错误:

  {
    "shard": 0,
    "index": "test",
    "node": "V3XGiCPAS0ej2PmYuk12qw",
    "reason": {
      "type": "query_shard_exception",
      "reason": "Failed to parse query [(pizza oven and/or pizza) OR (bread)]",
      "index_uuid": "OXSS-p_DTqeddnFkSjwWOw",
      "index": "test",
      "caused_by": {
        "type": "parse_exception",
        "reason": "parse_exception: Cannot parse '(pizza oven and/or pizza) OR (bread)': Lexical error at line 1, column 37.  Encountered: <EOF> after : \"/or pizza) OR (bread)\"",
        "caused_by": {
          "type": "token_mgr_error",
          "reason": "token_mgr_error: Lexical error at line 1, column 37.  Encountered: <EOF> after : \"/or pizza) OR (bread)\""
        }
      }
    }
  }

如何确保和/或不会破坏字符串查询?

1 个答案:

答案 0 :(得分:0)

http://localhost:9200/* 是查询字符串查询语言中的reserved character,您需要对其进行转义:

/