Elasticsearch is a Lucene-based search server. It provides a distributed multi-user-capable full-text search engine, based on a restful web interface. Elasticsearch is developed in Java, as the current popular enterprise-class search engine, used in cloud computing , can achieve real-time search, and has a stable, reliable, fast installation, ease of use and many other advantages, most enterprises are favored.
Elasicsearch can be indexed through the terminal, but I do the project with the terminal built index, and then use the Java API to insert data, always get the word breaker, the final solution is to build through the Java API Index, to avoid embarrassment, not much to say.
Suppose the basic data is a POI:
The properties are as follows:
Poi_index: Similar to ID
Poi_title: Place name (similar to: Wuhan University, Huazhong Science and Technology etc)
POI_LNG: Longitude
Poi_lat: Latitude
Poi_phone: Telephone (usually undefined)
Poi_address: Address (similar to: xx province xx xx district xx Road xx No.)
Poi_tags: Tags, categories (similar to: schools, hotels, companies, etc.)
as follows, some objects or variables are already set globally:
//Client SettingsSettings =Settings. Builder (). Put ("Cluster.name", "Cxy") //node name, set when ES is configured . Put ("Client.transport.sniff", "true"). build (); //Create clientClient=Newprebuilttransportclient (Settings). addtransportaddress (Newinetsockettransportaddress (Inetaddress.getbyname ("127.0.0.1"), 9300)); //with native as node //Creating Mappingsmapping =Xcontentfactory.jsonbuilder (). StartObject (). StartObject ("Properties") //. StartObject ("m_id"). Field ("type", "keyword"). EndObject (). StartObject ("Poi_index"). Field ("Type", "integer"). EndObject (). StartObject ("Poi_title"). Field ("Type", "Text"). Field ("Analyzer", "Ik_max_word"). EndObject (). StartObject ("Poi_address"). Field ("Type", "Text"). Field ("Analyzer", "Ik_max_word"). EndObject (). StartObject ("Poi_tags"). Field ("Type", "Text"). Field ("Analyzer", "Ik_max_word"). EndObject (). StartObject ("Poi_phone"). Field ("Type", "Text"). Field ("Analyzer", "Ik_max_word"). EndObject (). StartObject ("Poi_lng"). Field ("Type", "text"). EndObject (). StartObject ("Poi_lat"). Field ("Type", "text"). EndObject (). EndObject (). EndObject (); //pois: Index name Cxyword: type name (you can define it yourself) Putmappingrequest Putmap= Requests.putmappingrequest ("POIs"). Type ("Cxyword"). Source (mapping); //Create an indexClient.admin (). Indices (). Preparecreate ("POIs"). Execute (). Actionget (); //to add a map to an indexclient.admin (). Indices (). putmapping (Putmap). Actionget ();
This time the index is created, mapping can not drop, this is equivalent to a portal, the data in accordance with the set rules, Ik_max_word is the type of participle, the most fine-grained cutting, online search IK word breaker configuration, here do not say, the next is to insert data into the index.
ElasticSearch indexing with an IK word breaker (Java API)