Elasticsearch“ query_string”查询错误显示为“ Lexical error”

时间:2019-09-20 08:36:55

标签: elasticsearch lucene

应用版本
Elasticsearch:7.1版
Laravel:v5.8

操作系统版本:Ubuntu 18(服务器)/ Windows 10(开发PC)

Elasticsearch搜索API的“ query_string”查询返回诸如“词法错误”之类的错误消息-表示查询中存在错误。

复制步骤

a。我们正在使用包含 4629个字符(包括字母和符号,例如括号和双引号)的“ query_string”查询
b。当我们使用PHP和Python应用程序进行查询时,标题中提到的错误会弹出

error error2

主要问题

我在这里做错什么了吗?还是应用程序级错误/错误?一直在尝试使用“ simple_query_string”之类的替代方法,但是它具有不同的行为,因此我们非常热衷于使用Elasticsearch的 query_string 查询

这是查询

"query_string" => [
    "fields" => ['title', 'content'],
    "query" => """
        (("Salvador "Sal" San Buenaventura Panelo")) OR ("Christopher Lawrence Go") OR ("DILG Undersecretary Epimaco Densing") OR ("Rodolfo Fariñas") OR ("Francis Tolentino" AND ("De Lima" OR "Leila De Lima")) OR ("Reynaldo V. Umali" AND ("De Lima" OR "Leila De Lima")) OR ("Bong Revilla") OR (("Jose "Joe" Callangan Calida")) OR ("Gus S. Tambunting" OR "GusTambunting" AND ("De Lima" OR "Leila De Lima")) OR ("Ramon Bong Revilla" OR "Bong Revilla" AND ("De Lima" OR "Leila De Lima")) OR (Lacson) OR ("Francis Ng Tolentino") OR ("Jose Calida") OR ("José Ruperto Martín Marfori Andanar") OR ("Prospero Pichay Jr.") OR ("Pantaleon Alvarez" AND ("De Lima" OR "Leila De Lima")) OR ("Prospero Pichay" AND ("De Lima" OR "Leila De Lima")) OR ("Senator Vicente Sotto") OR ("Paolo "Pulong" Zimmerman Duterte") OR ("Prospero Arreza Pichay Jr.") OR ("Rudy Fariñas" AND ("De Lima" OR "Leila De Lima")) OR ("Paolo Duterte") OR ("Rudy Fariñas") OR ("Fredenil Castro") OR ("Salvador B. Belaro Jr.") OR ("Sen. Imee Marcos") OR ("Manny Pacquiao") OR ("Senator Aquilino "Koko" Pimentel III" OR "Sen. Aquilino "Koko" Pimentel III") OR ("Senator Aquilino Pimentel III" OR "Sen. Aquilino Pimentel III" OR "Senator Aquilino Pimentel") OR ("Senator Vicente C. Sotto III") OR ("Tito Sotto") OR ("Bato dela Rosa") OR ("Sen. Bato") OR ("Hon. Reynaldo V. Umali") OR ("Gus S. Tambunting") OR ("Tito Sotto" OR "Senator Vicente Sotto" AND ("De Lima" OR "Leila De Lima")) OR ("Bato dela Rosa" OR "Senator Ronald "Bato" dela Rosa"("De Lima" OR "Leila De Lima")) OR ("Bong Go" OR "Christopher Lawrence Go" AND ("De Lima" OR "Leila De Lima")) OR ("Paolo Duterte" AND ("De Lima" OR "Leila De Lima")) OR ("Fredenil H. Castro" OR "Fredenil Castro" AND ("De Lima" OR "Leila De Lima")) OR ("Koko Pimentel") OR ("Paolo Zimmerman Duterte") OR ("Pantaleon Diaz Alvarez") OR ("Salvador Belaro" AND ("De Lima" OR "Leila De Lima")) OR ("Ramon Revilla") OR ("Senator Bong Go") OR (Panfilo) OR ("Jose Callangan Calida") OR ("Salvador San Buenaventura Panelo") OR ("Pantaleon "Bebot" Diaz Alvarez") OR ("Fredenil H. Castro" OR "Fredenil Castro") OR ("Salvador Belaro Jr.") OR ("Salvador Belaro") OR ("Reynaldo V. Umali") OR ("Senator Koko Pimentel III) OR ("Sen. AND Koko AND Pimentel AND III" OR "Sen. AND Koko AND Pimentel") OR ("Bong AND Go") OR ("Ramon AND Bong AND Revilla") OR ("Senator AND Panfilo AND Lacson" OR "Panfilo AND Lacson" OR "Ping AND Lacson" ("De AND Lima" OR "Leila AND De AND Lima")) OR ("Manny AND Pacquiao" OR "Senator AND Manny AND Pacquiao" ("De AND Lima" OR "Leila AND De AND Lima")) OR ("Salvador AND Panelo" ("De AND Lima" OR "Leila AND De AND Lima")) OR ("Epimaco AND Densing" ("De AND Lima" OR "Leila AND De AND Lima")) OR ("Senator AND Sotto") OR ("Vicente AND Sotto") OR ("Panfilo AND Lacson" OR "Ping AND Lacson") OR ("Ronald AND dela AND Rosa") OR ("Senator AND Revilla") OR ("Prospero AND Pichay") OR ("Jose AND Calida" ("De AND Lima" OR "Leila AND De AND Lima")) OR ("Senator AND Francis AND Tolentino") OR ("Senator AND Ronald AND dela AND Rosa") OR ("Menardo AND Guevarra" OR "Menardo AND I. AND Guevarra") OR ("Rodolfo AND "Rudy" AND Castro AND Fariñas") OR ("Senator AND Imee AND Marcos" OR "Imee AND Marcos" ("De AND Lima" OR "Leila AND De AND Lima")) OR ("Gus AND S. AND Tambunting" ("De AND Lima" OR "Leila AND De AND Lima")) OR ("Ronald AND “Bato” AND dela AND Rosa") OR ("Senator AND Bato AND dela AND Rosa") OR ("Senator AND Ramon AND Revilla AND Jr.") OR ("Sen. AND Francis AND Tolentino") OR ("Francis AND Tolentino") OR (("María AND Imelda AND Josefa AND "Imee" AND Romualdez AND Marcos")) OR ("Pulong AND Duterte") OR ("Rodolfo AND Castro AND Fariñas") OR ("Menardo AND Guevarra" OR "Menardo AND I. AND Guevarra"("De AND Lima" OR "Leila AND De AND Lima")) OR ("Christopher AND Lawrence AND “Bong” AND Go") OR ("Senator AND Imee AND Marcos") OR ("Justice AND Secretary AND Menardo AND Guevarra" OR "Justice AND Secretary AND Menardo AND I. AND Guevarra") OR ("Epimaco AND Densing") OR ("Fredenil AND "Fred" AND H. AND Castro") OR ("Koko AND Pimentel" OR "Senator AND Aquilino AND Pimentel AND III" OR "Sen. AND Aquilino AND Pimentel AND III" OR "Senator AND Aquilino AND Pimentel" ("De AND Lima" OR "Leila AND De AND Lima")) OR ("Martín AND Andanar" ("De AND Lima" OR "Leila AND De AND Lima")) OR ("Senator AND Ronald AND "Bato" AND dela AND Rosa") OR ("Christopher AND Lawrence AND "Bong" AND Tesoro AND Go") OR ("Senator AND Christopher AND Lawrence AND "Bong" AND Tesoro AND Go") OR ("Senator AND Panfilo AND Lacson") OR ("Senator AND Manny AND Pacquiao") OR ("Salvador AND Panelo") OR ("Martín AND Andanar") OR ("Pantaleon AND Alvarez")
        """

1 个答案:

答案 0 :(得分:1)

""中删除双引号(query)并尝试如下操作,希望它能继续工作。

我的索引上的工作示例:

GET locations/_search
  {
    "size": 1,
    "sort": [
      {
        "_score": {
          "order": "desc"
        }
      },
      {
        "property_count": {
          "order": "desc"
        }
      }
    ],
    "query": {
      "bool": {
        "must": [
          {
            "match": {
              "country_code.keyword": "IT"
            }
          },
          {
            "query_string": {
              "fields": ["display","content"],
              "query": "((Salvador Sal San Buenaventura Panelo)) OR (Christopher Lawrence Go) OR (DILG Undersecretary Epimaco Densing) OR (Rodolfo Fariñas) OR (Francis Tolentino AND (De Lima OR Leila De Lima)) OR (Reynaldo V. Umali AND (De Lima OR Leila De Lima)) OR (Bong Revilla) OR ((Jose Joe Callangan Calida)) OR (Gus S. Tambunting OR GusTambunting AND (De Lima OR Leila De Lima)) OR (Ramon Bong Revilla OR Bong Revilla AND (De Lima OR Leila De Lima)) OR (Lacson) OR (Francis Ng Tolentino) OR (Jose Calida) OR (José Ruperto Martín Marfori Andanar) OR (Prospero Pichay Jr.) OR (Pantaleon Alvarez AND (De Lima OR Leila De Lima)) OR (Prospero Pichay AND (De Lima OR Leila De Lima)) OR (Senator Vicente Sotto) OR (Paolo Pulong Zimmerman Duterte) OR (Prospero Arreza Pichay Jr.) OR (Rudy Fariñas AND (De Lima OR Leila De Lima)) OR (Paolo Duterte) OR (Rudy Fariñas) OR (Fredenil Castro) OR (Salvador B. Belaro Jr.) OR (Sen. Imee Marcos) OR (Manny Pacquiao) OR (Senator Aquilino Koko Pimentel III OR Sen. Aquilino Koko Pimentel III) OR (Senator Aquilino Pimentel III OR Sen. Aquilino Pimentel III OR Senator Aquilino Pimentel) OR (Senator Vicente C. Sotto III) OR (Tito Sotto) OR (Bato dela Rosa) OR (Sen. Bato) OR (Hon. Reynaldo V. Umali) OR (Gus S. Tambunting) OR (Tito Sotto OR Senator Vicente Sotto AND (De Lima OR Leila De Lima)) OR (Bato dela Rosa OR Senator Ronald Bato dela Rosa(De Lima OR Leila De Lima)) OR (Bong Go OR Christopher Lawrence Go AND (De Lima OR Leila De Lima)) OR (Paolo Duterte AND (De Lima OR Leila De Lima)) OR (Fredenil H. Castro OR Fredenil Castro AND (De Lima OR Leila De Lima)) OR (Koko Pimentel) OR (Paolo Zimmerman Duterte) OR (Pantaleon Diaz Alvarez) OR (Salvador Belaro AND (De Lima OR Leila De Lima)) OR (Ramon Revilla) OR (Senator Bong Go) OR (Panfilo) OR (Jose Callangan Calida) OR (Salvador San Buenaventura Panelo) OR (Pantaleon Bebot Diaz Alvarez) OR (Fredenil H. Castro OR Fredenil Castro) OR (Salvador Belaro Jr.) OR (Salvador Belaro) OR (Reynaldo V. Umali) OR (Senator Koko Pimentel III) OR (Sen. AND Koko AND Pimentel AND III OR Sen. AND Koko AND Pimentel) OR (Bong AND Go) OR (Ramon AND Bong AND Revilla) OR (Senator AND Panfilo AND Lacson OR Panfilo AND Lacson OR Ping AND Lacson (De AND Lima OR Leila AND De AND Lima)) OR (Manny AND Pacquiao OR Senator AND Manny AND Pacquiao (De AND Lima OR Leila AND De AND Lima)) OR (Salvador AND Panelo (De AND Lima OR Leila AND De AND Lima)) OR (Epimaco AND Densing (De AND Lima OR Leila AND De AND Lima)) OR (Senator AND Sotto) OR (Vicente AND Sotto) OR (Panfilo AND Lacson OR Ping AND Lacson) OR (Ronald AND dela AND Rosa) OR (Senator AND Revilla) OR (Prospero AND Pichay) OR (Jose AND Calida (De AND Lima OR Leila AND De AND Lima)) OR (Senator AND Francis AND Tolentino) OR (Senator AND Ronald AND dela AND Rosa) OR (Menardo AND Guevarra OR Menardo AND I. AND Guevarra) OR (Rodolfo AND Rudy AND Castro AND Fariñas) OR (Senator AND Imee AND Marcos OR Imee AND Marcos (De AND Lima OR Leila AND De AND Lima)) OR (Gus AND S. AND Tambunting (De AND Lima OR Leila AND De AND Lima)) OR (Ronald AND “Bato” AND dela AND Rosa) OR (Senator AND Bato AND dela AND Rosa) OR (Senator AND Ramon AND Revilla AND Jr.) OR (Sen. AND Francis AND Tolentino) OR (Francis AND Tolentino) OR ((María AND Imelda AND Josefa AND Imee AND Romualdez AND Marcos)) OR (Pulong AND Duterte) OR (Rodolfo AND Castro AND Fariñas) OR (Menardo AND Guevarra OR Menardo AND I. AND Guevarra(De AND Lima OR Leila AND De AND Lima)) OR (Christopher AND Lawrence AND “Bong” AND Go) OR (Senator AND Imee AND Marcos) OR (Justice AND Secretary AND Menardo AND Guevarra OR Justice AND Secretary AND Menardo AND I. AND Guevarra) OR (Epimaco AND Densing) OR (Fredenil AND Fred AND H. AND Castro) OR (Koko AND Pimentel OR Senator AND Aquilino AND Pimentel AND III OR Sen. AND Aquilino AND Pimentel AND III OR Senator AND Aquilino AND Pimentel (De AND Lima OR Leila AND De AND Lima)) OR (Martín AND Andanar (De AND Lima OR Leila AND De AND Lima)) OR (Senator AND Ronald AND Bato AND dela AND Rosa) OR (Christopher AND Lawrence AND Bong AND Tesoro AND Go) OR (Senator AND Christopher AND Lawrence AND Bong AND Tesoro AND Go) OR (Senator AND Panfilo AND Lacson) OR (Senator AND Manny AND Pacquiao) OR (Salvador AND Panelo) OR (Martín AND Andanar) OR (Pantaleon AND Alvarez)"
            }
          }
        ]
      }
    },
    "_source": [
      "location_id",
      "display",
      "parent_path",
      "parent_location_id",
      "country",
      "country_code",
      "east",
      "west",
      "north",
      "south",
      "category"
    ]
  }

查看示例https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-query-string-query.html#query-string-query-ex-request