Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/328.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java SolrJ中缺少必需的唯一密钥字段错误_Java_Solr_Apache Poi_Solrj - Fatal编程技术网

Java SolrJ中缺少必需的唯一密钥字段错误

Java SolrJ中缺少必需的唯一密钥字段错误,java,solr,apache-poi,solrj,Java,Solr,Apache Poi,Solrj,我在我的项目中遇到了这个问题。我使用ApachePOI读取我的.xlsx excel文件,我想在我的Solr内核中为它们编制索引。我使用SolrInputDocument为读取文件编制索引。这是我的java代码 package org.solr; import org.apache.poi.ss.usermodel.*; import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.apache.poi.ss.usermodel.C

我在我的项目中遇到了这个问题。我使用ApachePOI读取我的.xlsx excel文件,我想在我的Solr内核中为它们编制索引。我使用SolrInputDocument为读取文件编制索引。这是我的java代码

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 java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Iterator;
import java.util.ArrayList;
import java.util.List;

import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.SolrQuery.ORDER;
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.response.QueryResponse;
import org.apache.solr.client.solrj.response.UpdateResponse;
import org.apache.solr.common.SolrDocumentList;
import org.apache.solr.common.SolrInputDocument;

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 {
        List dataList=getArchiveData();

    }

    private static List getArchiveData() throws SolrServerException {
        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";
            SolrClient solr=new HttpSolrClient.Builder(urlString).build();
            SolrInputDocument document=new SolrInputDocument();
            if(!document.isEmpty())
            {
                solr.deleteByQuery("*");
                solr.commit();
            }

            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.STRING) {
                        //System.out.println(currentCell.getStringCellValue());
                        for(int i=0;i<currentRow.getLastCellNum();i++)
                        {
                            if(currentCell.getColumnIndex()==1)
                            {
                                document.addField("NameAdded", currentCell.getStringCellValue());
                            }
                            else if(currentCell.getColumnIndex()==2)
                            {
                                document.addField("DateAdded", currentCell.getStringCellValue());
                            }
                            else if(currentCell.getColumnIndex()==3)
                            {
                                document.addField("NameModified", "");
                            }
                            else if(currentCell.getColumnIndex()==4)
                            {
                                document.addField("DateModified", "");
                            }
                            else if(currentCell.getColumnIndex()==5)
                            {
                                document.addField("strSO", currentCell.getStringCellValue());
                            }
                            else if(currentCell.getColumnIndex()==6)
                            {
                                document.addField("strCust", "");
                            }
                            else if(currentCell.getColumnIndex()==7)
                            {
                                document.addField("strOperator", "");
                            }
                            else if(currentCell.getColumnIndex()==8)
                            {
                                document.addField("PackName", currentCell.getStringCellValue());
                            }
                            else if(currentCell.getColumnIndex()==9)
                            {
                                document.addField("DocName", currentCell.getStringCellValue());
                            }
                            else if(currentCell.getColumnIndex()==10)
                            {
                                document.addField("DocType", currentCell.getStringCellValue());
                            }
                            else if(currentCell.getColumnIndex()==11)
                            {
                                document.addField("extType", currentCell.getStringCellValue());
                            }
                            else if(currentCell.getColumnIndex()==12)
                            {
                                document.addField("FileName", currentCell.getStringCellValue());
                            }
                            else if(currentCell.getColumnIndex()==13)
                            {
                                document.addField("FilePath", currentCell.getStringCellValue());
                            }
                            else if(currentCell.getColumnIndex()==14)
                            {
                                document.addField("NameDeleted", "");
                            }
                            else if(currentCell.getColumnIndex()==15)
                            {
                                document.addField("DateDeleted", "");
                            }
                            else if(currentCell.getColumnIndex()==16)
                            {
                                document.addField("intRev", currentCell.getStringCellValue());
                            }

                        }


                    } else if (currentCell.getCellTypeEnum() == CellType.NUMERIC) {
                        //System.out.println(currentCell.getNumericCellValue());
                        for(int k=0;k<currentRow.getLastCellNum();k++)
                        {
                            if(currentCell.getColumnIndex()==0)
                            {
                                document.addField("id", currentCell.getNumericCellValue());
                            }

                        }

                    }
                    UpdateResponse response=solr.add(document);
                    solr.commit();

                }
                //System.out.println();
                System.out.println(document.getField("id"));
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        catch(IOException e) {
            e.printStackTrace();
        }
        return dataList;
    }
}

当我使用SimplePostTool为文件编制索引时,并没有类似的错误,但我想在我的网页中更新我的核心

您的模式中可能有一个字段设置为唯一键,如下所示:

<uniqueKey>id</uniqueKey>
id
问题在于,在本例中,通过ApachePOI上载文档时,没有为该唯一字段发送值

您有两个选择:

  • 如果您确实有一个将是唯一的字段,请使用它。例如,使用copyField选项,如:
  • 
    
  • 由于您拥有实际的文档,您可以将UUID添加到“id”字段中

  • 创建一个唯一字段,如更新RequestHandler的UUID,如下所示:

  • <uniqueKey>id</uniqueKey>
    
    
    身份证件
    ...
    ...    
    uuid
    
    您还需要更新提取处理程序:

     <requestHandler name="/update/extract"
                  startup="lazy"
                  class="solr.extraction.ExtractingRequestHandler" >
    <lst name="defaults">
      ...
      <str name="update.chain">uuid</str>
    </lst>
    
    
    ...
    uuid
    

    您的架构中可能有一个字段设置为唯一键,如下所示:

    <uniqueKey>id</uniqueKey>
    
    id
    
    问题在于,在本例中,通过ApachePOI上载文档时,没有为该唯一字段发送值

    您有两个选择:

  • 如果您确实有一个将是唯一的字段,请使用它。例如,使用copyField选项,如:
  • 
    
  • 由于您拥有实际的文档,您可以将UUID添加到“id”字段中

  • 创建一个唯一字段,如更新RequestHandler的UUID,如下所示:

  • <uniqueKey>id</uniqueKey>
    
    
    身份证件
    ...
    ...    
    uuid
    
    您还需要更新提取处理程序:

     <requestHandler name="/update/extract"
                  startup="lazy"
                  class="solr.extraction.ExtractingRequestHandler" >
    <lst name="defaults">
      ...
      <str name="update.chain">uuid</str>
    </lst>
    
    
    ...
    uuid
    

    检查您准备的文档..它是否在创建和发布到solr时都有id字段…我检查了它,它有id字段
    id
    这是在我的模式中。xml检查您准备的文档..它是否在每次创建并发布到solr时都有id字段…我检查了它,它有id字段
    id
    这在我的模式中。xml首先感谢您的回答。我做了选项2,它给了我这样的错误
    unknown UpdateRequestProcessorChain:uuid
    我更新了答案以使用提取句柄中更新的uuid我更新了提取句柄,但它给了我第一个错误
    文档缺少必需的uniqueKey字段:id
    :(您的java代码设置了“id”)在某些情况下,document.addField(“id”,currentCell.getNumericCellValue());您是否尝试过始终使用您自己的UUID设置它?不,我也不知道我是怎么做的。首先感谢您的回答。我做了选项2,它会给我这样的错误
    unknown UpdateRequestProcessorChain:UUID
    我更新了答案以使用解压处理程序中更新的UUID我更新了解压处理程序,但它ves me第一个错误
    文档缺少必需的uniqueKey字段:id
    :(您的java代码在某些条件Document.addField(“id”,currentCell.getNumericCellValue())中设置“id”);您是否尝试过始终使用自己的UUID设置它?不,我也不知道我是如何做到的。