当我从solr进行查询时,发生了一个常见的异常,告诉我未定义的字段userId

2022-09-02 22:36:08

我正在开发一个Web应用程序。我使用弹簧mvc框架,cassandra和solr。我使用独立的solr,而不是solr cloud。我使用solr作为全文检索工具。我正面临着一个奇怪的问题,首先是.schema.xml

<schema name="KSP_core" version="1.1">
  <types>
    <fieldType name="uuid" class="solr.UUIDField" indexed="true" />  
    <fieldType name="date" class="solr.TrieDateField" precisionStep="0" positionIncrementGap="0"/>
    <fieldType name="int" class="solr.TrieIntField" precisionStep="0" positionIncrementGap="0"/>
    <fieldtype name="string"  class="solr.StrField" sortMissingLast="true" omitNorms="true"/>
    <fieldType name="long" class="solr.TrieLongField" precisionStep="0" positionIncrementGap="0"/>
    <fieldType name="double" class="solr.TrieDoubleField" precisionStep="0" positionIncrementGap="0"/>
  <fieldType name="text_ik" class="solr.TextField"> 
    <analyzer type="index" isMaxWordLength="true" class="org.wltea.analyzer.lucene.IKAnalyzer"/> 
    <analyzer type="query" isMaxWordLength="true" class="org.wltea.analyzer.lucene.IKAnalyzer"/> 
    </fieldType>
  </types>

 <fields>   
  <!-- general -->
  <field name="id"        type="uuid"    indexed="true"  stored="true"  multiValued="false" required="true"/>
  <field name="dbTable"      type="string"    indexed="true"  stored="true"  multiValued="false" /> 
  <field name="userId"      type="string"    indexed="true"  stored="true"  multiValued="false" /> 
  <field name="originatorId"      type="string"    indexed="true"  stored="true"  multiValued="false" />
  <field name="associatedObjectId"      type="string"    indexed="true"  stored="true"  multiValued="false" /> 
  <field name="createTime"      type="date"      indexed="true"  stored="true"/>
  <field name="status"     type="int"    indexed="true"  stored="true"  multiValued="false" />
  <field name="postType"      type="string"    indexed="true"  stored="true"  multiValued="false" /> 

  <!-- user activity -->
  <field name="userOperate" type="string" indexed="true" stored="true" multiValued="false"/>


  <!--user reputation-->
  <field name="reputation" type="int"      indexed="true"  stored="true"/>
  <field name="dayTime"      type="string"    indexed="true"  stored="true"/> 
  <field name="reason"      type="string"    indexed="true"  stored="true"  multiValued="false" /> 

  <!--user tags-->
  <field name="tagId"      type="string"    indexed="true"  stored="true"  multiValued="false" /> 
  <field name="tagName"      type="string"    indexed="true"  stored="true"  multiValued="false" /> 

  <field name="reputationOnTag" type="int"      indexed="true"  stored="true"/>
  <field name="_version_" type="long" indexed="true" stored="true"/>
 </fields>

  <uniqueKey>id</uniqueKey>
 <!-- field for the QueryParser to use when an explicit fieldname is absent -->
 <defaultSearchField>userId</defaultSearchField>

 <!-- SolrQueryParser configuration: defaultOperator="AND|OR" -->
 <solrQueryParser defaultOperator="OR"/>
</schema>

然后我向你展示solrconfig.xml

 <?xml version="1.0" encoding="UTF-8" ?>
<!--
 Licensed to the Apache Software Foundation (ASF) under one or more
 contributor license agreements.  See the NOTICE file distributed with
 this work for additional information regarding copyright ownership.
 The ASF licenses this file to You under the Apache License, Version 2.0
 (the "License"); you may not use this file except in compliance with
 the License.  You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
-->

<!--
 This is a stripped down config file used for a simple example...  
 It is *not* a good example to work from. 
-->
<config>
  <luceneMatchVersion>LUCENE_40</luceneMatchVersion>
  <!--  The DirectoryFactory to use for indexes.
        solr.StandardDirectoryFactory, the default, is filesystem based.
        solr.RAMDirectoryFactory is memory based, not persistent, and doesn't work with replication. -->
  <directoryFactory name="DirectoryFactory" class="${solr.directoryFactory:solr.StandardDirectoryFactory}"/>

  <dataDir>${solr.core0.data.dir:}</dataDir>

  <updateHandler class="solr.DirectUpdateHandler2">
    <updateLog>
      <str name="dir">${solr.core0.data.dir:}</str>
    </updateLog>
  </updateHandler>

  <!-- realtime get handler, guaranteed to return the latest stored fields 
    of any document, without the need to commit or open a new searcher. The current 
    implementation relies on the updateLog feature being enabled. -->
  <requestHandler name="/get" class="solr.RealTimeGetHandler">
    <lst name="defaults">
      <str name="omitHeader">true</str>
    </lst>
  </requestHandler>  

  <requestHandler name="/replication" class="solr.ReplicationHandler" startup="lazy" /> 

  <requestDispatcher handleSelect="true" >
    <requestParsers enableRemoteStreaming="false" multipartUploadLimitInKB="2048" />
  </requestDispatcher>

  <requestHandler name="standard" class="solr.StandardRequestHandler" default="true" />
  <requestHandler name="/analysis/field" startup="lazy" class="solr.FieldAnalysisRequestHandler" />
  <requestHandler name="/update" class="solr.UpdateRequestHandler"  />
  <requestHandler name="/admin/" class="org.apache.solr.handler.admin.AdminHandlers" />

  <requestHandler name="/admin/ping" class="solr.PingRequestHandler">
    <lst name="invariants">
      <str name="q">solrpingquery</str>
    </lst>
    <lst name="defaults">
      <str name="echoParams">all</str>
    </lst>
  </requestHandler>

  <!-- config for the admin interface --> 
  <admin>
    <defaultQuery>solr</defaultQuery>
  </admin>

</config>

当我从solr查询数据时,我使用solrj库来实现一般的查询。喜欢:

   String queryExpression = "*:*";
   String sortField = "createTime";
   String baseUrl = SolrUtil.getSolrBaseURL(solrHttpServer.getBaseURL());
   solrHttpServer.setBaseURL(baseUrl + "/" + coreName);
   SolrQuery query = new SolrQuery();
   query.setQuery(queryExpression);
   query.setSortField(sortField, SolrQuery.ORDER.asc);
   QueryResponse rsp = solrHttpServer.query(query);

以下代码是查询过程中的错误信息:

org.apache.solr.common.SolrException: undefined field userId
    at org.apache.solr.client.solrj.impl.HttpSolrServer.request(HttpSolrServer.java:401)
    at org.apache.solr.client.solrj.impl.HttpSolrServer.request(HttpSolrServer.java:181)
    at org.apache.solr.client.solrj.request.QueryRequest.process(QueryRequest.java:90)
    at org.apache.solr.client.solrj.SolrServer.query(SolrServer.java:301)
    at com.augmentum.ksp.solr.dao.impl.SolrBaseDaoImpl.query(SolrBaseDaoImpl.java:141)
    at com.augmentum.ksp.service.impl.TagStatsServiceImpl.getUserTagStats(TagStatsServiceImpl.java:50)
    at com.augmentum.ksp.controller.TagStatsController.getUserTagStats(TagStatsController.java:162)
    at sun.reflect.GeneratedMethodAccessor188.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:213)
    at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:126)
    at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:96)
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:617)
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:578)
    at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:923)
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852)
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
    at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:778)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.jasig.cas.client.util.AssertionThreadLocalFilter.doFilter(AssertionThreadLocalFilter.java:54)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.jasig.cas.client.util.HttpServletRequestWrapperFilter.doFilter(HttpServletRequestWrapperFilter.java:75)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.jasig.cas.client.validation.AbstractTicketValidationFilter.doFilter(AbstractTicketValidationFilter.java:201)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at com.augmentum.iaphelper.filter.AuthenticationFilter.doFilter(Unknown Source)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.jasig.cas.client.session.SingleSignOutFilter.doFilter(SingleSignOutFilter.java:76)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at com.augmentum.ksp.filter.I18nFilter.doFilter(I18nFilter.java:22)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
    at java.lang.Thread.run(Thread.java:619)

从信息中,我只知道我的控制器,服务和dao工作正常。非常奇怪的是,它在大多数时间里都能正常工作,但是错误必须在20次之内发生,我刷新了JSP页面,这让我很担心。我可以保证我的solr服务器正常启动。并且索引已加载。我不知道如何找到解决它的方法,因为我不知道问题的根源。

此外,还发生了许多与下面相同的错误,这次不是名为userId的字段,而是名为dbTable的字段。

org.apache.solr.common.SolrException: undefined field dbTable
    at org.apache.solr.client.solrj.impl.HttpSolrServer.request(HttpSolrServer.java:401)
    at org.apache.solr.client.solrj.impl.HttpSolrServer.request(HttpSolrServer.java:181)
    at org.apache.solr.client.solrj.request.QueryRequest.process(QueryRequest.java:90)
    at org.apache.solr.client.solrj.SolrServer.query(SolrServer.java:301)
    at com.augmentum.ksp.solr.dao.impl.SolrBaseDaoImpl.query(SolrBaseDaoImpl.java:135)
    at com.augmentum.ksp.service.impl.UserServiceImpl.listUserReputationByTime(UserServiceImpl.java:1222)
    at com.augmentum.ksp.controller.UserControler.listUserReputationByTime(UserControler.java:374)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:213)
    at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:126)
    at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:96)
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:617)
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:578)
    at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:923)
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852)
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
    at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:778)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.jasig.cas.client.util.AssertionThreadLocalFilter.doFilter(AssertionThreadLocalFilter.java:54)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.jasig.cas.client.util.HttpServletRequestWrapperFilter.doFilter(HttpServletRequestWrapperFilter.java:75)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.jasig.cas.client.validation.AbstractTicketValidationFilter.doFilter(AbstractTicketValidationFilter.java:201)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at com.augmentum.iaphelper.filter.AuthenticationFilter.doFilter(Unknown Source)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.jasig.cas.client.session.SingleSignOutFilter.doFilter(SingleSignOutFilter.java:76)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at com.augmentum.ksp.filter.I18nFilter.doFilter(I18nFilter.java:22)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
    at java.lang.Thread.run(Thread.java:619)

有没有人遇到同样的问题?


答案 1

正如我所看到的,你在代码中更改了baseUrl。正如您在评论中所说,您在同一页面上查询多个内核,并且所有这些内核都使用相同的.因此,您的解决方案中似乎缺乏同步,并且可能有两个请求同时运行,并且一个请求查询另一个请求的“核心”。HttpSolrServer

当然,您可以同步您的方法。但我认为,在您的情况下,最好不要每次都抽搐,而是为查询设置其他参数,这将用作您的。您需要在创建时设置一次:HttpSolrServerbaseUrlbaseUrlHttpSolrServer

HttpSolrServer solrHttpServer = new HttpSolrServer(baseUrl);

而不是为每个查询更改它,您将设置参数(代码的差异):

 String queryExpression = "*:*";
 String sortField = "createTime";
-String baseUrl = SolrUtil.getSolrBaseURL(solrHttpServer.getBaseURL());
-solrHttpServer.setBaseURL(baseUrl + "/" + coreName);
 SolrQuery query = new SolrQuery();
+query.set(CommonParams.QT, "/" + coreName + "/select");
 query.setQuery(queryExpression);
 query.setSortField(sortField, SolrQuery.ORDER.asc);
 QueryResponse rsp = solrHttpServer.query(query);

但最好的解决方案是为每个内核单独设置:HttpSolrServer

Map<String, HttpSolrServer> servers = new HashMap<String, HttpSolrServer>();
servers.put(coreName1, new HttpSolrServer(baseUrl + "/" + coreName1));
...

生成的代码更改:

 String queryExpression = "*:*";
 String sortField = "createTime";
-String baseUrl = SolrUtil.getSolrBaseURL(solrHttpServer.getBaseURL());
-solrHttpServer.setBaseURL(baseUrl + "/" + coreName);
 SolrQuery query = new SolrQuery();
 query.setQuery(queryExpression);
 query.setSortField(sortField, SolrQuery.ORDER.asc);
-QueryResponse rsp = solrHttpServer.query(query);
+QueryResponse rsp = servers.get(coreName).query(query);

答案 2

推荐