Issue Upgrading from 2.3.1 to 6.1.0


(Sam Schlaak) #1

Hello.

My application uses the Elasticsearch Java API to communicate with the cluster. Previously, when creating an index and assigning a mapping, it was done as follows:

create:
client.admin().indices().prepareCreate(indexName).execute().actionGet();

assign mapping:
PutMappingRequest pmr = Requests.putMappingRequest(indexName).type(userDocumentTypeName).source(userDocumentTypeMapping); client.admin().indices().putMapping(pmr).actionGet();

However, when updating to v6.1.0, this code does not work. It errors out with the message "Caused by: java.lang.IllegalArgumentException: mapping source must be pairs of fieldnames and properties definition."

My variable userDocumentTypeMapping is a string representation of a JSON object. It seems that this is not the format accepted any longer when creating a mapping. I am wondering what the proper format is and how I should go about converting my String to that format.


(David Pilato) #2

You can use I think setSource(userDocumentTypeMapping, XContentType.JSON) or something like this.

See


(Sam Schlaak) #3

This did the trick: (.source rather than .setSource)
PutMappingRequest pmr = Requests.putMappingRequest(indexName).type(userDocumentTypeName).source(userDocumentTypeMapping, XContentType.JSON);

That got me past the error I mentioned. Now I've got a different error regarding the mapping itself, but at least it's not the same one. I may be back if I get stuck again, haha. Thank you for the help, David!


(Sam Schlaak) #4

@dadoonet If you could please be of any help...I've run into another issue.

I'm trying to add a tokenizer and three analyzers to my index at creation time. Here's the code:
client.admin().indices().prepareCreate(indexName).setSettings(Settings.builder().loadFromSource(jsonBuilder()
.startObject()
.startObject("analysis")
.startObject("tokenizer")
.startObject("username_tokenizer")
.field("type", "nGram")
.field("min_gram", 1)
.field("max_gram", 80)
.endObject()
.endObject()
.startObject("analyzer")
.startObject("string_lowercase")
.field("type", "custom")
.field("tokenizer", "keyword")
.field("filter", new String[]{"lowercase"})
.endObject()
.endObject()
.startObject("analyzer")
.startObject("email")
.field("type", "custom")
.field("tokenizer", "uax_url_email")
.field("filter", new String[]{"standard","lowercase","stop"})
.endObject()
.endObject()
.startObject("analyzer")
.startObject("username")
.field("type", "custom")
.field("tokenizer", "username_tokenizer")
.field("filter", new String[]{"standard","lowercase"})
.endObject()
.endObject()
.endObject()
.endObject().string(), XContentType.JSON))
.execute().actionGet();

I'm getting the following error:

Caused by: com.fasterxml.jackson.core.JsonParseException: Duplicate field 'analyzer'
at [Source: {"analysis":{"tokenizer":{"username_tokenizer":{"type":"nGram","min_gram":1,"max_gram":80}},"analyzer":{"string_lowercase":{"type":"custom","tokenizer":"keyword","filter":["lowercase"]}},"analyzer":{"email":{"type":"custom","tokenizer":"uax_url_email","filter":["standard","lowercase","stop"]}},"analyzer":{"username":{"type":"custom","tokenizer":"username_tokenizer","filter":["standard","lowercase"]}}}}; line: 1, column: 198]
at com.fasterxml.jackson.core.json.JsonReadContext._checkDup(JsonReadContext.java:197) ~[jackson-core-2.6.2.jar:2.6.2]
at com.fasterxml.jackson.core.json.JsonReadContext.setCurrentName(JsonReadContext.java:192) ~[jackson-core-2.6.2.jar:2.6.2]
at com.fasterxml.jackson.core.json.ReaderBasedJsonParser.nextToken(ReaderBasedJsonParser.java:625) ~[jackson-core-2.6.2.jar:2.6.2]
at org.elasticsearch.common.xcontent.json.JsonXContentParser.nextToken(JsonXContentParser.java:52) ~[elasticsearch-6.1.0.jar:6.1.0]
at org.elasticsearch.common.settings.Settings.fromXContent(Settings.java:697) ~[elasticsearch-6.1.0.jar:6.1.0]
at org.elasticsearch.common.settings.Settings.fromXContent(Settings.java:703) ~[elasticsearch-6.1.0.jar:6.1.0]
at org.elasticsearch.common.settings.Settings.fromXContent(Settings.java:672) ~[elasticsearch-6.1.0.jar:6.1.0]
at org.elasticsearch.common.settings.Settings.access$500(Settings.java:81) ~[elasticsearch-6.1.0.jar:6.1.0]
at org.elasticsearch.common.settings.Settings$Builder.loadFromSource(Settings.java:1148) ~[elasticsearch-6.1.0.jar:6.1.0]

I suspect it may have something to do with creating multiple analyzers in the same JSON object. Is there a way to do this, or should I send each analyzer individually after creating the index? If so, what is the syntax to do this?


(David Pilato) #5

Please open a new thread.

And format your code using </> icon as explained in this guide and not the citation button. It will make your post more readable.

Or use markdown style like:

```
CODE
```

(Sam Schlaak) #6

Apologies, I'm new to the forums here. I will open a new topic on this.

Thanks.


(Neeraj Jain) #7

I have same task at my hand can you tell me how are you planning on migrating data from es2.3 to es 6 ??


(system) #8

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