如何修复ContentStreamUpdateRequest stream_size字段错误

时间:2019-03-25 06:13:11

标签: java solr apache-poi solrj

我正在使用Apache POI读取.xlsx文件,并且我想使用ContenStreamUpdateRequest在我的Solr核心中为该读取文件建立索引。但有一个问题。我的代码在这里。我将每个读取文件放在ArrayList中,并将数据放入ArrayList中。

package org.solr;

import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;

import static org.junit.Assert.assertNotNull;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.time.format.DateTimeFormatter;
import java.util.Iterator;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.UUID;

import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.SolrQuery;

import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.impl.HttpSolrClient;
import org.apache.solr.client.solrj.impl.XMLResponseParser;
import org.apache.solr.client.solrj.request.AbstractUpdateRequest;
import org.apache.solr.client.solrj.request.AbstractUpdateRequest.ACTION;
import org.apache.solr.client.solrj.request.ContentStreamUpdateRequest;
import org.apache.solr.client.solrj.request.UpdateRequest;
import org.apache.solr.client.solrj.response.UpdateResponse;
import org.apache.solr.common.SolrInputDocument;
import org.apache.solr.handler.dataimport.DateFormatTransformer;
import org.apache.solr.schema.DateValueFieldType;


public class PoiJava {
    private static final String fileName="C:\\Users\\FTK1187\\Desktop\\E-Archive - Copy\\TableArchive.xlsx";

    public static void main(String Args[]) throws SolrServerException, IOException {
        List dataList =new ArrayList();
        FileInputStream excelFile=null;
        try {
            excelFile = new FileInputStream(new File(fileName));
            Workbook workbook = new XSSFWorkbook(excelFile);
            Sheet datatypeSheet = workbook.getSheetAt(0);
            Iterator<Row> iterator = datatypeSheet.iterator();
            String urlString="http://localhost:8983/solr/archiveCore";
            HttpSolrClient solr=new HttpSolrClient.Builder(urlString).build();
            ((HttpSolrClient) solr).setParser(new XMLResponseParser());
            //SolrInputDocument document=new SolrInputDocument();
            ContentStreamUpdateRequest req = new ContentStreamUpdateRequest("/update/extract"); 
            solr.deleteByQuery("*");
            solr.commit();
            req.addFile(new File("C:\\Users\\FTK1187\\Desktop\\E-Archive - Copy\\TableArchive.csv"),"text/csv");
            while (iterator.hasNext()) {

                Row currentRow = iterator.next();
                Iterator<Cell> cellIterator = currentRow.iterator();

                while (cellIterator.hasNext()) {

                    Cell currentCell = cellIterator.next();
                    //getCellTypeEnum shown as deprecated for version 3.15
                    //getCellTypeEnum ill be renamed to getCellType starting from version 4.0
                    if (currentCell.getCellTypeEnum() == CellType.NUMERIC) {
                        //System.out.println(currentCell.getNumericCellValue());
                        ArrayList arrayID=new ArrayList();
                        arrayID.add(currentCell.getNumericCellValue());
                        for(int k=0;k<arrayID.size();k++)
                        {
                            if(currentCell.getColumnIndex()==0)
                            {
                                req.setParam("literal.id", String.valueOf(arrayID.get(k)));
                                req.setAction(AbstractUpdateRequest.ACTION.COMMIT, true, true);
                                solr.request(req);
                                //System.out.println(arrayID.get(k));
                            }

                        }

                    }
                    else if (currentCell.getCellTypeEnum() == CellType.STRING) {
                        ArrayList arrayAll=new ArrayList();
                        arrayAll.add(currentCell.getStringCellValue());
                        for(int i=0;i<arrayAll.size();i++)
                        {
                            if(currentCell.getColumnIndex()==1)
                            {
                                ArrayList arrayNameAdded=new ArrayList();
                                arrayNameAdded.add(currentCell.getStringCellValue());
                                req.setParam("literal.NameAdded", String.valueOf(arrayNameAdded.get(i)));
                                req.setAction(AbstractUpdateRequest.ACTION.COMMIT, true, true);
                                solr.request(req);
                                //System.out.println(arrayNameAdded.get(i));
                            }
                            else if(currentCell.getColumnIndex()==2)
                            {
                                ArrayList arrayDateAdded=new ArrayList();
                                arrayDateAdded.add(currentCell.getStringCellValue());
                                req.setParam("literal.DateAdded", String.valueOf(arrayDateAdded.get(i)));
                                req.setAction(AbstractUpdateRequest.ACTION.COMMIT, true, true);
                                solr.request(req);
                                //System.out.println(arrayDateAdded.get(i));
                            }
                            else if(currentCell.getColumnIndex()==3)
                            {
                                ArrayList arrayNameModified=new ArrayList();
                                arrayNameModified.add(currentCell.getStringCellValue());
                                req.setParam("literal.NameModified", String.valueOf(arrayNameModified.get(i)));
                                req.setAction(AbstractUpdateRequest.ACTION.COMMIT, true, true);
                                solr.request(req);
                            }
                            else if(currentCell.getColumnIndex()==4)
                            {
                                ArrayList arrayDateModified=new ArrayList();
                                arrayDateModified.add(currentCell.getStringCellValue());
                                req.setParam("literal.DateModified", String.valueOf(arrayDateModified.get(i)));
                                req.setAction(AbstractUpdateRequest.ACTION.COMMIT, true, true);
                                solr.request(req);
                                //System.out.println(arrayDateModified.get(i));
                            }
                            else if(currentCell.getColumnIndex()==5)
                            {
                                ArrayList arraystrSO=new ArrayList();
                                arraystrSO.add(currentCell.getStringCellValue());
                                req.setParam("literal.strSO", String.valueOf(arraystrSO.get(i)));
                                req.setAction(AbstractUpdateRequest.ACTION.COMMIT, true, true);
                                solr.request(req);
                                //System.out.println(arraystrSO.get(i));
                            }
                            else if(currentCell.getColumnIndex()==6)
                            {
                                ArrayList arraystrCust=new ArrayList();
                                arraystrCust.add(currentCell.getStringCellValue());
                                req.setParam("literal.strCust", String.valueOf(arraystrCust.get(i)));
                                req.setAction(AbstractUpdateRequest.ACTION.COMMIT, true, true);
                                solr.request(req);
                            }
                            else if(currentCell.getColumnIndex()==7)
                            {
                                ArrayList arraystrOperator=new ArrayList();
                                arraystrOperator.add(currentCell.getStringCellValue());
                                req.setParam("literal.strOperator", String.valueOf(arraystrOperator.get(i)));
                                req.setAction(AbstractUpdateRequest.ACTION.COMMIT, true, true);
                                solr.request(req);
                            }
                            else if(currentCell.getColumnIndex()==8)
                            {
                                ArrayList arrayPackName=new ArrayList();
                                arrayPackName.add(currentCell.getStringCellValue());
                                req.setParam("literal.PackName", String.valueOf(arrayPackName.get(i)));
                                req.setAction(AbstractUpdateRequest.ACTION.COMMIT, true, true);
                                solr.request(req);
                                //System.out.println(arrayPackName.get(i));
                            }
                            else if(currentCell.getColumnIndex()==9)
                            {
                                ArrayList arrayDocName=new ArrayList();
                                arrayDocName.add(currentCell.getStringCellValue());
                                req.setParam("literal.DocName", String.valueOf(arrayDocName.get(i)));
                                req.setAction(AbstractUpdateRequest.ACTION.COMMIT, true, true);
                                solr.request(req);
                                //System.out.println(arrayDocName.get(i));
                            }
                            else if(currentCell.getColumnIndex()==10)
                            {
                                ArrayList arrayDocType=new ArrayList();
                                arrayDocType.add(currentCell.getStringCellValue());
                                req.setParam("literal.DocType", String.valueOf(arrayDocType.get(i)));
                                req.setAction(AbstractUpdateRequest.ACTION.COMMIT, true, true);
                                solr.request(req);
                                //System.out.println(arrayDocType.get(i));
                            }
                            else if(currentCell.getColumnIndex()==11)
                            {
                                ArrayList arrayextType=new ArrayList();
                                arrayextType.add(currentCell.getStringCellValue());
                                req.setParam("literal.extType", String.valueOf(arrayextType.get(i)));
                                req.setAction(AbstractUpdateRequest.ACTION.COMMIT, true, true);
                                solr.request(req);
                                //System.out.println(arrayextType.get(i));
                            }
                            else if(currentCell.getColumnIndex()==12)
                            {
                                ArrayList arrayFileName=new ArrayList();
                                arrayFileName.add(currentCell.getStringCellValue());
                                req.setParam("literal.FileName", String.valueOf(arrayFileName.get(i)));
                                req.setAction(AbstractUpdateRequest.ACTION.COMMIT, true, true);
                                solr.request(req);
                                //System.out.println(arrayFileName.get(i));
                            }
                            else if(currentCell.getColumnIndex()==13)
                            {
                                ArrayList arrayFilePath=new ArrayList();
                                arrayFilePath.add(currentCell.getStringCellValue());
                                req.setParam("literal.FilePath", String.valueOf(arrayFilePath.get(i)));
                                req.setAction(AbstractUpdateRequest.ACTION.COMMIT, true, true);
                                solr.request(req);
                                //System.out.println(arrayFilePath.get(i));
                            }
                            else if(currentCell.getColumnIndex()==14)
                            {
                                ArrayList arrayNameDeleted=new ArrayList();
                                arrayNameDeleted.add(currentCell.getStringCellValue());
                                req.setParam("literal.NameDeleted", String.valueOf(arrayNameDeleted.get(i)));
                                req.setAction(AbstractUpdateRequest.ACTION.COMMIT, true, true);
                                solr.request(req);
                            }
                            else if(currentCell.getColumnIndex()==15)
                            {
                                ArrayList arrayDateDeleted=new ArrayList();
                                arrayDateDeleted.add(currentCell.getStringCellValue());
                                req.setParam("literal.DateDeleted", String.valueOf(arrayDateDeleted.get(i)));
                                req.setAction(AbstractUpdateRequest.ACTION.COMMIT, true, true);
                                solr.request(req);
                            }
                            else if(currentCell.getColumnIndex()==16)
                            {
                                ArrayList arrayintRev=new ArrayList();
                                arrayintRev.add(currentCell.getStringCellValue());
                                req.setParam("literal.intRev", String.valueOf(arrayintRev.get(i)));
                                req.setAction(AbstractUpdateRequest.ACTION.COMMIT, true, true);
                                solr.request(req);
                                //System.out.println(arrayintRev.get(i));
                            }

                        }


                    } 


                }


            }
            req.setAction(AbstractUpdateRequest.ACTION.COMMIT, true, true);
            solr.request(req);

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        catch(IOException e) {
            e.printStackTrace();
        }

    }

}

我收到此错误。我没有任何名为“ stream_size”的字段。为什么会给我这个错误?

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
SLF4J: Failed to load class "org.slf4j.impl.StaticMDCBinder".
SLF4J: Defaulting to no-operation MDCAdapter implementation.
SLF4J: See http://www.slf4j.org/codes.html#no_static_mdc_binder for further details.
Exception in thread "main" org.apache.solr.client.solrj.impl.HttpSolrClient$RemoteSolrException: Error from server at http://localhost:8983/solr/archiveCore: ERROR: [doc=5927bfa2-0ee2-4cca-95cb-47ddccdb9285] unknown field 'stream_size'
    at org.apache.solr.client.solrj.impl.HttpSolrClient.executeMethod(HttpSolrClient.java:610)
    at org.apache.solr.client.solrj.impl.HttpSolrClient.request(HttpSolrClient.java:279)
    at org.apache.solr.client.solrj.impl.HttpSolrClient.request(HttpSolrClient.java:268)
    at org.apache.solr.client.solrj.SolrClient.request(SolrClient.java:1219)
    at org.solr.PoiJava.main(PoiJava.java:96)

0 个答案:

没有答案