ElasticSearch indexing with an IK word breaker (Java API)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.