Create a TCP Client
Client client = new Transportclient () . addtransportaddress (New inetsockettransportaddress ( "localhost", 9300 ));
Create index Client.admin (). Indices (). Preparecreate ("pages"). Execute (). Actionget ();
CREATE INDEX structure Xcontentbuilder builder= Xcontentfactory.jsonbuilder (). StartObject () .startobject ("Sina"). StartObject (" Properties "). StartObject (" Article_title "). Field (" Type "," string "). Field (" Store "," yes "). Field (" Analyzer "," IK "). Field ("Index", "analyzed"). EndObject (). StartObject ("Article_content"). Field ("Type", "string"). Field ("Store", "no" ). Field ("Analyzer", "IK"). Field ("Index", "analyzed"). EndObject (). StartObject ("Article_url"). Field ("Type", "string "). Field (" Store "," yes "). Field (" Index "," not_analyzed "). EndObject (). EndObject (). EndObject (). EndObject (); Putmappingrequest mapping = requests.putmappingrequest ("pages"). Type ("Sina"). Source (builder); Client.admin (). Indices (). putmapping (mapping). Actionget ();
Add Index data indexresponse response = Client.prepareindex ("pages", "Sina", null). SetSource (Jsonbuilder (). StartObject () . Field ("Article_title", Bytes.tostring (R.getvalue ("article". GetBytes (), "title". GetBytes ())) . Field (" Article_content ", Bytes.tostring (R.getvalue (" article ". GetBytes ()," content ". GetBytes ())) . Field (" Article_ URL ", bytes.tostring (R.getvalue (" article ". GetBytes ()," url ". GetBytes ())). EndObject ()). execute (). Actionget (); Client.close ();
Elastic Search Java API CREATE INDEX structure, add index