Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {
- "test" : {
- "general" : {
- "properties" : {
- "message" : {
- "type" : "string"
- },
- "source" : {
- "type" : "string"
- }
- }
- }
- }
- }
- {
- "test" : {
- "general" : {
- "properties" : {
- "message" : {
- "type" : "string",
- "index" : "not_analyzed"
- },
- "source" : {
- "type" : "string"
- }
- }
- }
- }
- }
- client.admin().indices().prepareCreate("test")
- .setSettings(getGrantSettings());
- static Settings getGrantSettings(){
- JSONObject settingSource = new JSONObject();
- try{
- settingSource.put("mapping", new JSONObject()
- .put("message", new JSONObject()
- .put("type", "string")
- .put("index", "not_analyzed")
- ));
- } catch (JSONException e){
- e.printStackTrace();
- }
- Settings set = ImmutableSettings.settingsBuilder()
- .loadFromSource(settingSource.toString()).build();
- return set;
- }
- XContentBuilder mapping = jsonBuilder()
- .startObject()
- .startObject("general")
- .startObject("properties")
- .startObject("message")
- .field("type", "string")
- .field("index", "not_analyzed")
- .endObject()
- .startObject("source")
- .field("type","string")
- .endObject()
- .endObject()
- .endObject()
- .endObject();
- PutMappingResponse putMappingResponse = client.admin().indices()
- .preparePutMapping("test")
- .setType("general")
- .setSource(mapping)
- .execute().actionGet();
- client.admin().indices().create(new CreateIndexRequest("indexname")).actionGet();
- PutMappingResponse putMappingResponse = client.admin().indices()
- .preparePutMapping("indexname")
- .setType("indextype")
- .setSource(jsonBuilder().prettyPrint()
- .startObject()
- .startObject("indextype")
- .startObject("properties")
- .startObject("country").field("type", "string").field("index", "not_analyzed").endObject()
- .endObject()
- .endObject()
- .endObject())
- .execute().actionGet();
- IndexResponse response1 = client.prepareIndex("indexname", "indextype")
- .setSource(buildIndex())
- .execute()
- .actionGet();
- // Now "Sri Lanka" considered to be a single country :)
- SearchResponse response = client.prepareSearch("indexname"
- ).addAggregation(AggregationBuilders.terms("countryfacet").field("country")).setSize(30).execute().actionGet();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement