0
0

More than 3 years have passed since last update.

SolrJ でドキュメントをインポートする

Posted at

Code


import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.impl.HttpSolrClient;
import org.apache.solr.client.solrj.response.UpdateResponse;
import org.apache.solr.common.SolrInputDocument;

public class HelloDocumentAdd2 {

    public static void main(String[] args) throws SolrServerException, IOException {

        String urlString = "http://localhost:8983/solr/sandbox";
        SolrClient solr = new HttpSolrClient.Builder(urlString).build();

        SolrInputDocument document = new SolrInputDocument();
        document.addField("id", "5");
        document.addField("field_text_en", "This is test. for Date formatting ");
        document.addField("field_location_string", "ja");

        {
            String dateNow = (new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss")).format(new Date());
            System.err.println(dateNow);
            document.addField("field_date", dateNow);
        }

        UpdateResponse response = solr.add(document); // throws SolrServerException,IOException

        System.err.println(response);

        // Remember to commit your changes!

        solr.commit();

    }

}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0