Sunday, 15 June 2014

Elasticsearch initial configuration in Java code or in external script? -


I am learning elastic search and I have started a new project. Now I wonder where to add mapping etc., where should I add initial code etc. Do you create an external script that holds different curl commands and then runs on it, or for example Java project has a self package where your configuration code is and then when you need to run it for? Which approach is most suitable and why?

The mapping that I use the XContentBuilder

  {"Tweets": {"Properties": {"message" "Type": "String", "Store": "Yes" , "Index": "analyzed", "value_value": "not"}}}}    

  Public void putMappingFromString (string index, string type, string mapping) {div class = "post-text" itemprop = "text"> 

indeseadmin client IACC = maltent (). Administrator () Index (); PutMappingRequestBuilder pmrb = New PutMappingRequestBuilder (iac); Pmrb.setIndices (index); Pmrb.setType (type); Pmrb.setSource (mapping); ListenableActionFuture & LT; PutMappingResponse & gt; Laf = pmrb.execute (); PutMappingResponse pmr = laf.actionGet (); Pmr.getAcknowledged (); }

You can obtain mapping for an index from the cluster state (indirectly):

  public string mismapping (string index, string type ) Throws EsuException {ClusterState CS = getClient (). Administrator () Cluster () ReadyState () SetFilterIndices (index) .execute () ActionGet (). GetState (); Index metadata IMD = C Metadata (). Index (index); If (IMD == faucet) {new ESUIDXOntexExistException (index); } MappingMetaTata mmd = imd.mapping (type); If (mmd == tap) {new EsuTypeDoesNotExistException (index, type); } String mapping = ""; {Mapping = mmd.source (). Try the string (); } Hold (IOException e) {mapping = "{\" "+ e.toString () +" \ "}"; } Return mapping; }   

If you store your mapping as a resource on your class path, then it allows your mapping to be processed with your source code < / Div>

No comments:

Post a Comment