Skip to content

Instantly share code, notes, and snippets.

@sameek
Created January 16, 2012 12:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sameek/1620578 to your computer and use it in GitHub Desktop.
Save sameek/1620578 to your computer and use it in GitHub Desktop.
java code for define custom mapping
try {
XContentBuilder stopwordfilter = null;
XContentBuilder indexSettings = null;
stopwordfilter=XContentFactory.jsonBuilder();
stopwordfilter.startObject()
.startObject("stopwordfilter")
.field("type","stop")
.field("stopwords_path","F:\\resources\\stopwords_eng.txt")
.field("ignore_case","true")
.endObject();
indexSettings = XContentFactory.jsonBuilder();
indexSettings.startObject()
.startObject("index")
.startObject("analysis")
.startObject("analyzer")
.startObject("search_analyzer")
.field("type","custom")
.field("tokenizer", "whitespace")
.field("filter", new String[]{"stopwordfilter"})
.field("filter",stopwordfilter)
.endObject().endObject().endObject().endObject().endObject();
UpdateSettingsRequestBuilder settingsRequest =client.admin().indices().prepareUpdateSettings();
UpdateSettingsRequestBuilder setSettings = settingsRequest.setSettings(indexSettings.string());
UpdateSettingsResponse settingsResponse =setSettings.execute().actionGet();
System.out.println(settingsResponse);
} catch (IOException e) {
e.printStackTrace();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment