SOLR/SOLRJ index updates by ID

Source: Internet
Author: User
Tags solr

The recent project requires SOLR to be able to implement an index based on the ID of the local field update, so on the Internet to find some information, finally found the method, and encapsulated, simple sharing under the Main method body (here is the SOLRJ operation index through the SOLR API):

...

public void Updateindex () {
Jsonarray content = new Jsonarray ();
Jsonobject json = new Jsonobject ();
Jsonobject set = new Jsonobject ();
Jsonobject Set2 = new Jsonobject ();
Jsonobject Set3 = new Jsonobject ();
Jsonobject set5 = new Jsonobject ();
Jsonobject inc = new Jsonobject (); Increment on a field
Jsonobject add1 = new Jsonobject ();
Jsonobject add2 = new Jsonobject ();
Jsonobject add3 = new Jsonobject ();
Jsonobject add4 = new Jsonobject ();

try {
Set.put ("Set", "1 after Test");
Set2.put ("Set", "New home Name");
Set3.put ("Set", "New home Name 2");
Set5.put ("Set", "modified Xinhua bookstore Three filial mouth");
Add1.put ("Add", "Del1"); {"Add": "Cyberpunk"}
Add2.put ("Add", "Del2");
Add3.put ("Add", "Del3");
Add4.put ("Add", "hotpot leader");

Json.put ("id", "1")
. put ("Name_ss", Set3)
. put ("name_s", Set2)
. Put ("name", set)
. put ("Ca1_ss", ADD1)
. put ("Cat2_ss", ADD2)
. put ("Cat3_ss", ADD3)
. put ("Content_smart_max_2", ADD4)
. put ("Content_smart_max_2", SET5);
Content.add (JSON);
SYSTEM.OUT.PRINTLN (content);
SYSTEM.OUT.PRINTLN (JSON);
} catch (Final Jsonexception e) {
}
Sendhttpmessage (Base_url + "/update", content.tostring ());
}


@Test
public void Test {
Updatesolrfield atmoupdate = new Updatesolrfield ("Http://172.37.37.21:8080/solr/core2");
Atmoupdate.addindex ();
Atmoupdate.updateindex ();
}


Add: Ability to add indexed content to the original field, note that the field at this time is multi-valued, and if this field does not exist, a field is created in the current doc;

INC: Ability to increase in existing field capacity

Set: Replaces the original field index content, and if the field does not exist at this point, the field is created in the current doc.

The full code class can be downloaded to http://download.csdn.net/detail/u013035314/8825933 (download is available directly).

SOLR/SOLRJ index updates by ID

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.