阅读目录

本文版权归mephisto和博客园共有,欢迎转载,但须保留此段声明,并给出原文链接,谢谢合作。

文章是哥(mephisto)写的,SourceLink

 

     在cdh集成的solr cloud中,我们可以通过solr管理界面进行查询,也可以通过java的api进行查询,但查询过程中,如果是时间类型的,可能会存在两者在界面上看上去不一致的问题,两者时间刚好相差本地的时区。

创建collection

一:上传配置文件

  为了模拟现象,我们设置如下solr文档结构

Hadoop技巧(04):简易处理solr date 时区问题

solrctl instancedir --create date_demo /data/solr_s

二:创建collection

solrctl collection --create date_demo -s 2 -m 2 -r 2

创建完后solr的collection如下

Hadoop技巧(04):简易处理solr date 时区问题

模拟程序

一:编写程序

  编写模拟插入程序。为了容易查看,只插入2条数据。

  这里我们使用的solr版本为4.10.3。

    private void insert() throws SolrServerException, IOException,
            ParseException {
        String zhHost = "master1/solr";

        CloudSolrServer cloudSolrServer = new CloudSolrServer(zhHost);

        cloudSolrServer.setDefaultCollection("date_demo");

        String id_1 = UUID.randomUUID().toString().replaceAll("-", "")
                .toUpperCase();
        String name_1 = "1点前+8";
        Date createDate_1 = sdfDate.parse("2016-12-30 00:11:12");
        String day_1 = sdfDay.format(createDate_1);

        String id_2 = UUID.randomUUID().toString().replaceAll("-", "")
                .toUpperCase();
        String name_2 = "1点后+8";
        Date createDate_2 = sdfDate.parse("2016-12-30 10:13:14");
        String day_2 = sdfDay.format(createDate_2);

        SolrInputDocument solrInputDocument1 = create(id_1, name_1, day_1,
                createDate_1);
        SolrInputDocument solrInputDocument2 = create(id_2, name_2, day_2,
                createDate_2);

        cloudSolrServer.add(solrInputDocument1);
        cloudSolrServer.add(solrInputDocument2);
        cloudSolrServer.commit();

        System.out.println("success");
    }
View Code

相关文章:

  • 2022-12-23
  • 2022-02-22
  • 2021-09-04
  • 2022-12-23
  • 2022-12-23
  • 2021-10-24
  • 2021-05-30
  • 2021-12-18
猜你喜欢
  • 2022-12-23
  • 2022-01-11
  • 2021-10-28
  • 2018-05-11
  • 2020-05-19
  • 2021-06-05
  • 2021-08-21
相关资源
相似解决方案