[es/search] failed: [x_content_parse_exception] [2:4] Unexpected character ('\' (code 92)): was expecting double-quote

I am using elastic version 8+ with spring boot elasticsearch 5.2.0 dependency. I want to query my index with Odata $filter. I have configured my parser for Odata and it's generating below query json for following query: $filter=degreeLevel eq masters

{
  "bool" : {
    "must" : [
      {
        "match" : {
          "degreeLevel" : {
            "query" : "masters",
            "operator" : "OR",
            "prefix_length" : 0,
            "max_expansions" : 50,
            "fuzzy_transpositions" : true,
            "lenient" : false,
            "zero_terms_query" : "NONE",
            "auto_generate_synonyms_phrase_query" : true,
            "boost" : 1.0
          }
        }
      }
    ],
    "adjust_pure_negative" : true,
    "boost" : 1.0
  }
}

But from cluster I am getting 400 with following error:

Resolved [UncategorizedElasticsearchException: [es/search] failed: [x_content_parse_exception] [2:4] Unexpected character ('\' (code 92)): was expecting double-quote to start field name
 at [Source: (byte[])"{
  \"bool\" : {
    \"must\" : [
      {
        \"match\" : {
          \"degreeLevel\" : {
            \"query\" : \"masters\",
            \"operator\" : \"OR\",
            \"prefix_length\" : 0,
            \"max_expansions\" : 50,
            \"fuzzy_transpositions\" : true,
            \"lenient\" : false,
            \"zero_terms_query\" : \"NONE\",
            \"auto_generate_synonyms_phrase_query\" : true,
            \"boost\" : 1.0
          }
        }
      }
    ],

Welcome!

You need to use the same version for the client and the server.

Here is my elastic cluster version:

{
  "name": "c167c8e1dda1",
  "cluster_name": "docker-cluster",
  "cluster_uuid": "Dn8-_6pySM23uucR0ejdpQ",
  "version": {
    "number": "8.8.1",
    "build_flavor": "default",
    "build_type": "docker",
    "build_hash": "f8edfccba429b6477927a7c1ce1bc6729521305e",
    "build_date": "2023-06-05T21:32:25.188464208Z",
    "build_snapshot": false,
    "lucene_version": "9.6.0",
    "minimum_wire_compatibility_version": "7.17.0",
    "minimum_index_compatibility_version": "7.0.0"
  },
  "tagline": "You Know, for Search"
}

And my pom file dependencies for elasticsearch:

<dependency>
			<groupId>org.springframework.data</groupId>
			<artifactId>spring-data-elasticsearch</artifactId>
			<version>5.2.0</version>
			<exclusions>
				<exclusion>
					<groupId>org.elasticsearch</groupId>
					<artifactId>elasticsearch</artifactId>
				</exclusion>
				<exclusion>
					<groupId>org.elasticsearch.client</groupId>
					<artifactId>
						elasticsearch-rest-client
					</artifactId>
				</exclusion>
			</exclusions>
		</dependency>

		<dependency>
			<version>8.8.1</version>
			<groupId>org.elasticsearch</groupId>
			<artifactId>elasticsearch</artifactId>
		</dependency>

		<dependency>
			<groupId>org.elasticsearch.client</groupId>
			<artifactId>elasticsearch-rest-client</artifactId>
			<version>8.8.1</version>
		</dependency>

I believe I am using same version on both.

Could you share the output of:

mvn dependency:tree

This exception means that the request being sent to Elasticsearch contains those \ escape characters, so it isn't valid JSON. I've no idea where that's coming from tho, but it's something in the client. I suspect it might be related to the Spring Boot Elasticsearch usage tho, the maintainers for that library don't visit us here much so you might need to ask for their help directly.

+- org.springframework.boot:spring-boot-starter:jar:3.2.3:compile
[INFO] |  +- org.springframework.boot:spring-boot:jar:3.2.3:compile
[INFO] |  +- org.springframework.boot:spring-boot-autoconfigure:jar:3.2.3:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter-logging:jar:3.2.3:compile
[INFO] |  |  +- ch.qos.logback:logback-classic:jar:1.4.14:compile
[INFO] |  |  |  \- ch.qos.logback:logback-core:jar:1.4.14:compile
[INFO] |  |  +- org.apache.logging.log4j:log4j-to-slf4j:jar:2.21.1:compile
[INFO] |  |  \- org.slf4j:jul-to-slf4j:jar:2.0.12:compile
[INFO] |  +- jakarta.annotation:jakarta.annotation-api:jar:2.1.1:compile
[INFO] |  +- org.springframework:spring-core:jar:6.1.4:compile
[INFO] |  |  \- org.springframework:spring-jcl:jar:6.1.4:compile
[INFO] |  \- org.yaml:snakeyaml:jar:2.2:compile
[INFO] +- org.springframework.boot:spring-boot-starter-test:jar:3.2.3:test
[INFO] |  +- org.springframework.boot:spring-boot-test:jar:3.2.3:test
[INFO] |  +- org.springframework.boot:spring-boot-test-autoconfigure:jar:3.2.3:test
[INFO] |  +- com.jayway.jsonpath:json-path:jar:2.9.0:test
[INFO] |  +- jakarta.xml.bind:jakarta.xml.bind-api:jar:4.0.1:test
[INFO] |  |  \- jakarta.activation:jakarta.activation-api:jar:2.1.2:test
[INFO] |  +- net.minidev:json-smart:jar:2.5.0:compile
[INFO] |  |  \- net.minidev:accessors-smart:jar:2.5.0:compile
[INFO] |  |     \- org.ow2.asm:asm:jar:9.3:compile
[INFO] |  +- org.assertj:assertj-core:jar:3.24.2:test
[INFO] |  |  \- net.bytebuddy:byte-buddy:jar:1.14.12:runtime
[INFO] |  +- org.awaitility:awaitility:jar:4.2.0:test
[INFO] |  +- org.hamcrest:hamcrest:jar:2.2:test
[INFO] |  +- org.junit.jupiter:junit-jupiter:jar:5.10.2:test
[INFO] |  |  +- org.junit.jupiter:junit-jupiter-api:jar:5.10.2:test
[INFO] |  |  |  +- org.opentest4j:opentest4j:jar:1.3.0:test
[INFO] |  |  |  +- org.junit.platform:junit-platform-commons:jar:1.10.2:test
[INFO] |  |  |  \- org.apiguardian:apiguardian-api:jar:1.1.2:test
[INFO] |  |  +- org.junit.jupiter:junit-jupiter-params:jar:5.10.2:test
[INFO] |  |  \- org.junit.jupiter:junit-jupiter-engine:jar:5.10.2:test
[INFO] |  |     \- org.junit.platform:junit-platform-engine:jar:1.10.2:test
[INFO] |  +- org.mockito:mockito-core:jar:5.7.0:test
[INFO] |  |  +- net.bytebuddy:byte-buddy-agent:jar:1.14.12:test
[INFO] |  |  \- org.objenesis:objenesis:jar:3.3:test
[INFO] |  +- org.mockito:mockito-junit-jupiter:jar:5.7.0:test
[INFO] |  +- org.skyscreamer:jsonassert:jar:1.5.1:test
[INFO] |  |  \- com.vaadin.external.google:android-json:jar:0.0.20131108.vaadin1:test
[INFO] |  +- org.springframework:spring-test:jar:6.1.4:test
[INFO] |  \- org.xmlunit:xmlunit-core:jar:2.9.1:test
[INFO] +- io.springfox:springfox-spring-webflux:jar:3.0.0:compile
[INFO] |  +- com.fasterxml:classmate:jar:1.6.0:compile
[INFO] |  +- org.slf4j:slf4j-api:jar:2.0.12:compile
[INFO] |  +- org.springframework.plugin:spring-plugin-core:jar:2.0.0.RELEASE:compile
[INFO] |  +- org.springframework.plugin:spring-plugin-metadata:jar:2.0.0.RELEASE:compile
[INFO] |  +- io.springfox:springfox-spi:jar:3.0.0:runtime
[INFO] |  +- io.springfox:springfox-schema:jar:3.0.0:runtime
[INFO] |  +- io.springfox:springfox-core:jar:3.0.0:runtime
[INFO] |  \- io.springfox:springfox-spring-web:jar:3.0.0:runtime
[INFO] |     \- io.github.classgraph:classgraph:jar:4.8.83:runtime
[INFO] +- org.springframework.boot:spring-boot-starter-webflux:jar:3.2.3:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter-json:jar:3.2.3:compile
[INFO] |  |  +- com.fasterxml.jackson.datatype:jackson-datatype-jdk8:jar:2.15.4:compile
[INFO] |  |  +- com.fasterxml.jackson.datatype:jackson-datatype-jsr310:jar:2.15.4:compile
[INFO] |  |  \- com.fasterxml.jackson.module:jackson-module-parameter-names:jar:2.15.4:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter-reactor-netty:jar:3.2.3:compile
[INFO] |  |  \- io.projectreactor.netty:reactor-netty-http:jar:1.1.16:compile
[INFO] |  |     +- io.netty:netty-codec-http:jar:4.1.107.Final:compile
[INFO] |  |     |  +- io.netty:netty-common:jar:4.1.107.Final:compile
[INFO] |  |     |  +- io.netty:netty-buffer:jar:4.1.107.Final:compile
[INFO] |  |     |  +- io.netty:netty-transport:jar:4.1.107.Final:compile
[INFO] |  |     |  +- io.netty:netty-codec:jar:4.1.107.Final:compile
[INFO] |  |     |  \- io.netty:netty-handler:jar:4.1.107.Final:compile
[INFO] |  |     +- io.netty:netty-codec-http2:jar:4.1.107.Final:compile
[INFO] |  |     +- io.netty:netty-resolver-dns:jar:4.1.107.Final:compile
[INFO] |  |     |  +- io.netty:netty-resolver:jar:4.1.107.Final:compile
[INFO] |  |     |  \- io.netty:netty-codec-dns:jar:4.1.107.Final:compile
[INFO] |  |     +- io.netty:netty-resolver-dns-native-macos:jar:osx-x86_64:4.1.107.Final:compile
[INFO] |  |     |  \- io.netty:netty-resolver-dns-classes-macos:jar:4.1.107.Final:compile
[INFO] |  |     +- io.netty:netty-transport-native-epoll:jar:linux-x86_64:4.1.107.Final:compile
[INFO] |  |     |  +- io.netty:netty-transport-native-unix-common:jar:4.1.107.Final:compile
[INFO] |  |     |  \- io.netty:netty-transport-classes-epoll:jar:4.1.107.Final:compile
[INFO] |  |     \- io.projectreactor.netty:reactor-netty-core:jar:1.1.16:compile
[INFO] |  |        \- io.netty:netty-handler-proxy:jar:4.1.107.Final:compile
[INFO] |  |           \- io.netty:netty-codec-socks:jar:4.1.107.Final:compile
[INFO] |  +- org.springframework:spring-web:jar:6.1.4:compile
[INFO] |  \- org.springframework:spring-webflux:jar:6.1.4:compile
[INFO] |     \- io.projectreactor:reactor-core:jar:3.6.3:compile
[INFO] +- org.springframework.boot:spring-boot-starter-web:jar:3.2.3:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter-tomcat:jar:3.2.3:compile
[INFO] |  |  +- org.apache.tomcat.embed:tomcat-embed-core:jar:10.1.19:compile
[INFO] |  |  +- org.apache.tomcat.embed:tomcat-embed-el:jar:10.1.19:compile
[INFO] |  |  \- org.apache.tomcat.embed:tomcat-embed-websocket:jar:10.1.19:compile
[INFO] |  \- org.springframework:spring-webmvc:jar:6.1.4:compile
[INFO] +- org.springframework.boot:spring-boot-starter-actuator:jar:3.2.3:compile
[INFO] |  +- org.springframework.boot:spring-boot-actuator-autoconfigure:jar:3.2.3:compile
[INFO] |  |  \- org.springframework.boot:spring-boot-actuator:jar:3.2.3:compile
[INFO] |  +- io.micrometer:micrometer-observation:jar:1.12.3:compile
[INFO] |  |  \- io.micrometer:micrometer-commons:jar:1.12.3:compile
[INFO] |  \- io.micrometer:micrometer-jakarta9:jar:1.12.3:compile
[INFO] |     \- io.micrometer:micrometer-core:jar:1.12.3:compile
[INFO] |        \- org.latencyutils:LatencyUtils:jar:2.0.3:runtime
[INFO] +- org.springframework.data:spring-data-elasticsearch:jar:5.2.0:compile
[INFO] |  +- org.springframework:spring-tx:jar:6.1.4:compile
[INFO] |  +- org.springframework.data:spring-data-commons:jar:3.2.3:compile
[INFO] |  +- co.elastic.clients:elasticsearch-java:jar:8.10.4:compile
[INFO] |  |  +- com.google.code.findbugs:jsr305:jar:3.0.2:compile
[INFO] |  |  +- jakarta.json:jakarta.json-api:jar:2.1.3:compile
[INFO] |  |  +- org.eclipse.parsson:parsson:jar:1.0.0:compile
[INFO] |  |  \- io.opentelemetry:opentelemetry-api:jar:1.31.0:runtime
[INFO] |  |     \- io.opentelemetry:opentelemetry-context:jar:1.31.0:runtime
[INFO] |  +- org.elasticsearch.client:elasticsearch-rest-client:jar:8.10.4:compile
[INFO] |  |  +- org.apache.httpcomponents:httpasyncclient:jar:4.1.5:compile
[INFO] |  |  \- org.apache.httpcomponents:httpcore-nio:jar:4.4.16:compile
[INFO] |  +- com.fasterxml.jackson.core:jackson-core:jar:2.15.4:compile
[INFO] |  \- com.fasterxml.jackson.core:jackson-databind:jar:2.15.4:compile
[INFO] |     \- com.fasterxml.jackson.core:jackson-annotations:jar:2.15.4:compile
[INFO] +- Internal-package:compile
[INFO] |  +- org.opensearch:opensearch:jar:1.3.9:compile
[INFO] |  |  +- org.opensearch:opensearch-core:jar:1.3.9:compile
[INFO] |  |  +- org.opensearch:opensearch-secure-sm:jar:1.3.9:compile
[INFO] |  |  +- org.opensearch:opensearch-x-content:jar:1.3.9:compile
[INFO] |  |  |  +- com.fasterxml.jackson.dataformat:jackson-dataformat-smile:jar:2.15.4:compile
[INFO] |  |  |  +- com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:jar:2.15.4:compile
[INFO] |  |  |  \- com.fasterxml.jackson.dataformat:jackson-dataformat-cbor:jar:2.15.4:compile
[INFO] |  |  +- org.opensearch:opensearch-geo:jar:1.3.9:compile
[INFO] |  |  +- org.apache.lucene:lucene-core:jar:8.10.1:compile
[INFO] |  |  +- org.apache.lucene:lucene-analyzers-common:jar:8.10.1:compile
[INFO] |  |  +- org.apache.lucene:lucene-backward-codecs:jar:8.10.1:compile
[INFO] |  |  +- org.apache.lucene:lucene-grouping:jar:8.10.1:compile
[INFO] |  |  +- org.apache.lucene:lucene-highlighter:jar:8.10.1:compile
[INFO] |  |  +- org.apache.lucene:lucene-join:jar:8.10.1:compile
[INFO] |  |  +- org.apache.lucene:lucene-memory:jar:8.10.1:compile
[INFO] |  |  +- org.apache.lucene:lucene-misc:jar:8.10.1:compile
[INFO] |  |  +- org.apache.lucene:lucene-queries:jar:8.10.1:compile
[INFO] |  |  +- org.apache.lucene:lucene-queryparser:jar:8.10.1:compile
[INFO] |  |  +- org.apache.lucene:lucene-sandbox:jar:8.10.1:compile
[INFO] |  |  +- org.apache.lucene:lucene-spatial-extras:jar:8.10.1:compile
[INFO] |  |  +- org.apache.lucene:lucene-spatial3d:jar:8.10.1:compile
[INFO] |  |  +- org.apache.lucene:lucene-suggest:jar:8.10.1:compile
[INFO] |  |  +- org.opensearch:opensearch-cli:jar:1.3.9:compile
[INFO] |  |  |  \- net.sf.jopt-simple:jopt-simple:jar:5.0.4:compile
[INFO] |  |  +- com.carrotsearch:hppc:jar:0.8.1:compile
[INFO] |  |  +- joda-time:joda-time:jar:2.12.2:compile
[INFO] |  |  +- com.tdunning:t-digest:jar:3.2:compile
[INFO] |  |  +- org.hdrhistogram:HdrHistogram:jar:2.1.9:compile
[INFO] |  |  \- net.java.dev.jna:jna:jar:5.5.0:compile
[INFO] |  +- org.opensearch.client:spring-data-opensearch:jar:1.3.0:compile
[INFO] |  |  \- org.opensearch.client:opensearch-rest-high-level-client:jar:2.11.0:compile
[INFO] |  |     +- org.opensearch.client:opensearch-rest-client:jar:2.11.0:compile
[INFO] |  |     +- org.opensearch.plugin:mapper-extras-client:jar:2.11.0:compile
[INFO] |  |     +- org.opensearch.plugin:parent-join-client:jar:2.11.0:compile
[INFO] |  |     +- org.opensearch.plugin:aggs-matrix-stats-client:jar:2.11.0:compile
[INFO] |  |     +- org.opensearch.plugin:rank-eval-client:jar:2.11.0:compile
[INFO] |  |     \- org.opensearch.plugin:lang-mustache-client:jar:2.11.0:compile
[INFO] |  |        \- com.github.spullara.mustache.java:compiler:jar:0.9.10:compile

OpenSearch/OpenDistro are AWS run products and differ from the original Elasticsearch and Kibana products that Elastic builds and maintains. You may need to contact them directly for further assistance. See What is OpenSearch and the OpenSearch Dashboard? | Elastic for more details.

(This is an automated response from your friendly Elastic bot. Please report this post if you have any suggestions or concerns :elasticheart: )

Does that mean the request should not contain those forward slashes?
I see the ElasticsearchConfiguration class from org.springframework.data.elasticsearch.client.elc using JacksonJsonMapper class, maybe it's coming from there.

Correct (except that they're backslashes).

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.