Solr 6.0.0 - SolrCloud java存储数据作为分片簇中的数组 - 为什么

时间:2016-06-24 11:21:00

标签: solr

我用Ensemble和单个zookeepr开始我的solr myCloudData集合。

2个solr节点,1个Ensemble zookeeper独立节点 集合:myCloudData,分片:2,复制:2

默认情况下,数据已验证并存储为数组 为什么我的字符串数据存储为数组 - 这是集群,分片等的行为?

我错了还是对的?请告诉我。

以下给出的样本数据。

            package com.test.solr.pojo;

            import java.util.ArrayList;
            import java.util.List;
            import java.util.Random;
            import java.util.UUID;
            import java.util.concurrent.TimeUnit;

            import org.apache.solr.client.solrj.impl.CloudSolrClient;

            public class ProductMainPopulateCloudDataAndIndexer {
                public static void main(String[] args) {
                    try {
                        // Commit Data Index  Within 'specified' MilliSecs
                        int commitWithinMs = 15000; // 15 secs
                        List<Product> beans = new ArrayList<>(5000); // Every 5000 records, rehash
                        //long _1CroreRecords = 10000000;
                        long _1CroreRecords = 1000000;
                        //String zkHosts = "64.101.49.57:2181/solr";
                        String zkHosts = "localhost:9983";
                        CloudSolrClient solrCloudClient = new CloudSolrClient(zkHosts);
                        //solrCloudClient.setDefaultCollection("myCloudData");
                        solrCloudClient.setDefaultCollection("gettingstarted");

                        System.out.println(" 1 crore records " + _1CroreRecords);
                        long start = System.nanoTime();
                        for (long i = 1; i <= _1CroreRecords; i++) {
                            //System.out.println(" In Progress Record :  " +  (i + 1));
                            UUID idGenearte =  UUID.randomUUID();
                            Random r = new Random(System.currentTimeMillis());
                            Product product = new Product();
                            product.setId("" + idGenearte + Math.abs(r.nextLong()));
                            product.setProductID(i);
                            product.setProductName("Test Product " + (i));
                            product.setMonth(i);
                            product.setYear(i);
                            product.setShippingMethod(i);
                            beans.add(product);
                            if (i % 75000 == 0) {
                                System.out.println("Flush to Solr for Index  every 75000 records : " + i);
                                //solrCloudClient.addBeans(beans, commitWithinMs);
                                solrCloudClient.addBeans(beans);
                                beans = new ArrayList<>(5000);
                            }
                        }
                        // add Product objects to the list
                        solrCloudClient.addBeans(beans);
                        solrCloudClient.close();
                        long end =  System.nanoTime();
                        System.out.println("Elapsed Time in Minutes "  + TimeUnit.NANOSECONDS.toMinutes(end - start));
                    } catch (Exception e) {
                        e.printStackTrace();
                    }

                }

            }

       {
          "responseHeader": {
            "status": 0,
            "QTime": 25,
            "params": {
              "indent": "true",
              "q": "*:*",
              "_": "1466766630689",
              "wt": "json"
            }
          },
          "response": {
            "numFound": 1000000,
            "start": 0,
            "maxScore": 1,
            "docs": [
              {
                "id": "054e6ca0-4963-41f0-a407-67e284ca94704458339022992077222",
                "productID": [
                  237391
                ],
                "productName": [
                  "Test Product 237391"
                ],
                "year": [
                  237391
                ],
                "month": [
                  237391
                ],
                "shippingMethod": [
                  237391
                ],
                "_version_": 1538016061817880600
              },
              {
                "id": "894d13ae-0f97-461f-b2fe-2a6788e1eb614458339022992077222",
                "productID": [
                  237394
                ],
                "productName": [
                  "Test Product 237394"
                ],
                "year": [
                  237394
                ],
                "month": [
                  237394
                ],
                "shippingMethod": [
                  237394
                ],
                "_version_": 1538016061849337900
              },
              {
                "id": "71a75cbf-cfae-4956-8ac8-64324bb94a344458339022992077222",
                "productID": [
                  237396
                ],
                "productName": [
                  "Test Product 237396"
                ],
                "year": [
                  237396
                ],
                "month": [
                  237396
                ],
                "shippingMethod": [
                  237396
                ],
                "_version_": 1538016061849337900
              },
              {
                "id": "523dc90c-0e76-48e3-98c7-618bb7b4f2234458339022992077222",
                "productID": [
                  237399
                ],
                "productName": [
                  "Test Product 237399"
                ],
                "year": [
                  237399
                ],
                "month": [
                  237399
                ],
                "shippingMethod": [
                  237399
                ],
                "_version_": 1538016061849337900
              },
              {
                "id": "ada85003-9a77-469c-95f6-d12953bc30c54458339022992077222",
                "productID": [
                  237400
                ],
                "productName": [
                  "Test Product 237400"
                ],
                "year": [
                  237400
                ],
                "month": [
                  237400
                ],
                "shippingMethod": [
                  237400
                ],
                "_version_": 1538016061849337900
              },
              {
                "id": "725bbb67-952d-4eca-8b28-dadcbdd0922b4458339022992077222",
                "productID": [
                  237401
                ],
                "productName": [
                  "Test Product 237401"
                ],
                "year": [
                  237401
                ],
                "month": [
                  237401
                ],
                "shippingMethod": [
                  237401
                ],
                "_version_": 1538016061849337900
              },
              {
                "id": "82b0b1a6-945e-41ca-9c04-4f32ddee07974458339022992077222",
                "productID": [
                  237403
                ],
                "productName": [
                  "Test Product 237403"
                ],
                "year": [
                  237403
                ],
                "month": [
                  237403
                ],
                "shippingMethod": [
                  237403
                ],
                "_version_": 1538016061849337900
              },
              {
                "id": "5e1de036-9feb-420b-b27c-3fb2e80e81f54458339022992077222",
                "productID": [
                  237404
                ],
                "productName": [
                  "Test Product 237404"
                ],
                "year": [
                  237404
                ],
                "month": [
                  237404
                ],
                "shippingMethod": [
                  237404
                ],
                "_version_": 1538016061849337900
              },
              {
                "id": "8734a60a-0436-4160-ab18-94755e2552534458339022992077222",
                "productID": [
                  237406
                ],
                "productName": [
                  "Test Product 237406"
                ],
                "year": [
                  237406
                ],
                "month": [
                  237406
                ],
                "shippingMethod": [
                  237406
                ],
                "_version_": 1538016061849337900
              },
              {
                "id": "5798ea1d-f179-4e08-bf42-73f84b8fc0144458339022992077222",
                "productID": [
                  237407
                ],
                "productName": [
                  "Test Product 237407"
                ],
                "year": [
                  237407
                ],
                "month": [
                  237407
                ],
                "shippingMethod": [
                  237407
                ],
                "_version_": 1538016061849337900
              }
            ]
          }
        }

1 个答案:

答案 0 :(得分:1)

这是因为你必须提到multiValued=true

将其标记为multiValued=false并检查相同内容。