Java API vs Jackson dependencies : Can it be a problem?


(Xavier Facq) #1

Hi all,

I have a Java Maven project with:

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

I run a simple prepareIndex, where source is an HashMap, no special field:

				IndexResponse ir = client.prepareIndex(documentType.getIndexName(), documentType.getDocumentType(), Long.toString(2222222))
					.setSource(source)
					.get();

No problem here, ir.getShardInfo().getFailed() = 0, and my document is well indexed.

BUT, there is an error into the IndexResponse (I think it's when decoding the response):

  IndexResponse[index=myindex,type=mydoc,id=2222222,version=11,created=false,shards=Error building toString out of XContent: com.fasterxml.jackson.core.JsonGenerationException: Can not write a field name, expecting a value
      at com.fasterxml.jackson.core.JsonGenerator._reportError(JsonGenerator.java:1886)
      at com.fasterxml.jackson.core.json.UTF8JsonGenerator.writeFieldName(UTF8JsonGenerator.java:235)
      at org.elasticsearch.common.xcontent.json.JsonXContentGenerator.writeFieldName(JsonXContentGenerator.java:152)
      at org.elasticsearch.common.xcontent.XContentBuilder.field(XContentBuilder.java:264)
      at org.elasticsearch.common.xcontent.XContentBuilder.field(XContentBuilder.java:255)
      at org.elasticsearch.common.xcontent.XContentBuilder.startObject(XContentBuilder.java:169)
      at org.elasticsearch.action.ActionWriteResponse$ShardInfo.toXContent(ActionWriteResponse.java:147)
      at org.elasticsearch.common.Strings.toString(Strings.java:1103)
      at org.elasticsearch.common.Strings.toString(Strings.java:1089)
      at org.elasticsearch.action.ActionWriteResponse$ShardInfo.toString(ActionWriteResponse.java:164)
      at java.lang.String.valueOf(String.java:2849)
      at java.lang.StringBuilder.append(StringBuilder.java:128)
      at org.elasticsearch.action.index.IndexResponse.toString(IndexResponse.java:118)
    ...
  ]

I found here a solution pretty recent: http://stackoverflow.com/questions/39679400/elastic-search-bulk-index-java-api-not-working

Here is another same problem, but only solved in 5x version: https://github.com/elastic/elasticsearch/issues/20853

When I split dependencies, there is no more JsonGenerationException, but I wonder if it could be a problem to do not use the Jackson version "linked" to the Elasticsearch version.

So my question is simple : Should I stay with this error, or should I split dependencies ?

Thx,
Xavier


(Xavier Facq) #2

More info here : https://github.com/elastic/elasticsearch/pull/21319


(Nik Everett) #3

Personally I'd work around the issue until you are ready to upgrade. If it isn't a big deal then I'd upgrade sooner rather than later because the 2.x -> 5.x upgrade requires a full cluster restart. And because you are using the transport client it requires that your app upgrade as well.....


(Xavier Facq) #4

It seems that there is a quickfix applied in the 5.x :

Do you think it can/will be applied to the 2.4 branch ?

    @Override
    public String toString() {
        return "ShardInfo{" +
            "total=" + total +
             ", successful=" + successful +
             ", failures=" + Arrays.toString(failures) +
            '}';            
    }

Thank you !
Xavier


(Nik Everett) #5

I don't think we have any plans to do so. We might, but I don't think so.


(Xavier Facq) #6

To avoid the exception, my Maven is now:

    <jackson.version>2.7.8</jackson.version>

...

	<dependency>
		<groupId>org.elasticsearch</groupId>
		<artifactId>elasticsearch</artifactId>
		<version>2.4.2</version>
		<exclusions>
			<exclusion>
				<groupId>com.fasterxml.jackson.core</groupId>
				<artifactId>jackson-core</artifactId>
			</exclusion>
			<exclusion>
				<groupId>com.fasterxml.jackson.dataformat</groupId>
				<artifactId>jackson-dataformat-smile</artifactId>
			</exclusion>
			<exclusion>
				<groupId>com.fasterxml.jackson.dataformat</groupId>
				<artifactId>jackson-dataformat-yaml</artifactId>
			</exclusion>
			<exclusion>
				<groupId>com.fasterxml.jackson.dataformat</groupId>
				<artifactId>jackson-dataformat-cbor</artifactId>
			</exclusion>
		</exclusions>
	</dependency>
	<dependency>
		<groupId>com.fasterxml.jackson.core</groupId>
		<artifactId>jackson-core</artifactId>
		<version>${jackson.version}</version>
	</dependency>
	<dependency>
		<groupId>com.fasterxml.jackson.dataformat</groupId>
		<artifactId>jackson-dataformat-smile</artifactId>
		<version>${jackson.version}</version>
	</dependency>
	<dependency>
		<groupId>com.fasterxml.jackson.dataformat</groupId>
		<artifactId>jackson-dataformat-yaml</artifactId>
		<version>${jackson.version}</version>
	</dependency>
	<dependency>
		<groupId>com.fasterxml.jackson.dataformat</groupId>
		<artifactId>jackson-dataformat-cbor</artifactId>
		<version>${jackson.version}</version>
	</dependency>

(system) #7

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