我是SOLR和MONGODB的新手.
我试图使用DataImportHandler将mongodb中的数据索引到SOLR,但我找不到我需要遵循的确切步骤.
你能否帮助我获得使用DataImportHandler将MongoDB索引到Solr的确切步骤?
SolrVersion - solr-4.6.0
MongoDB版本 - 2.2.7
我的Solr数据源是一个SQL数据库,其中主键是复合的(即它是两个字段).
这对我的主要DIH来说很好query
,我只是连接字段,这就成了我的Solr主键.但是,从文档中我不清楚如何编写delta-import查询来支持这一点.
文档建议我需要两个查询 - 一个用于查找已更改行的主键,另一个用于查找与每个键对应的单个文档.但是没有示例显示复合键.
理想情况下,我根本不需要这两个单独的查询,如果将这两个查询简单地组合在一起,那么它将减少数据库上的负载,以便query
和之间的唯一区别deltaQuery
是WHERE
基于过滤器的子句last_changed
.
所以,如果我的主要query
是:
SELECT key1 || key2 as pk FROM table
Run Code Online (Sandbox Code Playgroud)
相关deltaQuery
(和/或deltaImportQuery
)的外观是什么样的?
我尝试添加该WHERE
子句,但在查询运行后,我得到了一个关于缺失的警告deltaImportQuery
,然后是一个空指针异常.
我现在拥有的是两个双重的filds:
<field name="x_geo_x_coordinate" type="double" indexed="true" stored="true" default="0"/>
<field name="x_geo_y_coordinate" type="double" indexed="true" stored="true" default="0"/>
Run Code Online (Sandbox Code Playgroud)
和我想要的:一个位置字段中的2个双精度值:
<field name="x_geo" type="location" indexed="true" stored="true" default="0.0,0.0"/>
Run Code Online (Sandbox Code Playgroud)
到目前为止我尝试了什么并且不起作用:
<copyField source="*_coordinate" dest="x_geo"/>
<copyField source="x_geo_str" dest="x_geo"/>
Run Code Online (Sandbox Code Playgroud)
有什么简单的解决 提前致谢!
我在使用Solr4中的dataImportHandler生成UUID时遇到问题.我试图从现有的MySQL数据库导入.
我的schema.xml包含:
<fields>
<field name="uuid" type="uuid" indexed="true" stored="true" required="true" />
<field name="id" type="string" indexed="true" stored="true" required="true"/>
<field name="address" type="text_general" indexed="true" stored="true"/>
<field name="city" type="text_general" indexed="true" stored="true" />
<field name="county" type="string" indexed="true" stored="true" />
<field name="lat" type="text_general" indexed="true" stored="true" />
<field name="lng" type="text_general" indexed="true" stored="true" termVectors="true" termPositions="true" termOffsets="true" />
<field name="price" type="float" indexed="true" stored="true"/>
<field name="bedrooms" type="float" indexed="true" stored="true" />
<field name="image" type="string" indexed="true" stored="true"/>
<field name="region" type="location_rpt" indexed="true" stored="true" />
<defaultSearchField>address</defaultSearchField>
<field name="_version_" type="long" indexed="true" stored="true"/>
<field name="text" type="text_general" indexed="true" …
Run Code Online (Sandbox Code Playgroud) 使用Solr 4,可以对索引中的现有文档进行原子(部分)更新.即,可以匹配文档ID并替换仅一个字段的内容,或者将更多条目添加到多值字段:http://wiki.apache.org/solr/Atomic_Updates
可以从DataImportHandler(DIH)完成原子更新吗?
我正在使用Solr 7.4.0并使用DIH方法索引数据.
在data-config.xml中查询.
<entity name="Test" query="Select Names,Test_Value1,Test_Value2,Test_Value3 from TestTable">
<field column="Names" name="Names" splitBy="," />
<field column="Test_*" name="Test_*" splitBy="," />
</entity>
Run Code Online (Sandbox Code Playgroud)
Schema.xml的
<field name="Names" type="string" multiValued="true" indexed="true" />
<dynamicField name="Test_*" type="string" multiValued="true" indexed="true" />
Run Code Online (Sandbox Code Playgroud)
完成索引后,名称可轻松分离如下,并根据需要将值显示为multiValue.
例如
"Names":["Demo1",
"Demo2"]
Run Code Online (Sandbox Code Playgroud)
但是当使用动态字段作为字符串类型multiValue时.它在索引中显示此结果.
"Test_Value1":["Test 1, Test 2, Test 3"],
Run Code Online (Sandbox Code Playgroud)
但我需要这个结果如下.
"Test_Value1":["Test 1", "Test 2", "Test 3"],
Run Code Online (Sandbox Code Playgroud)
如何分离动态字段值的值,如上所示.
我正在尝试在JBoss 5.1上设置Solr 3.5.0.一切都很好.我将war复制到deploy dir中,将dist和contrib目录中的所有依赖项复制到lib(或更早部署)目录中.
我可以启动服务器,一切正常,但每当我想激活DataImportHandler来索引我的数据库中的数据时,我都会收到错误.
基本上我所做的就是我复制的是我从example/example-DIH/solr/db复制一个核心(或整个例子,这没关系),我在solr.xml中注册核心,在启动时我收到一个错误:
15:17:10,707 SEVERE [RequestHandlers] org.apache.solr.common.SolrException: Error Instantiating Request Handler, org.apache.solr.handler.dataimport.DataImportHandler is not a org.apache.solr.request.SolrRequestHandler
at org.apache.solr.core.SolrCore.createInstance(SolrCore.java:427)
at org.apache.solr.core.SolrCore.createRequestHandler(SolrCore.java:461)
at org.apache.solr.core.RequestHandlers.initHandlersFromConfig(RequestHandlers.java:157)
Run Code Online (Sandbox Code Playgroud)
我很确定我的请求处理程序定义是正确的,但只是为了确定:
<requestHandler name="/dataimport" class="org.apache.solr.handler.dataimport.DataImportHandler">
<lst name="defaults">
<str name="config">dataimport.xml</str>
</lst>
Run Code Online (Sandbox Code Playgroud)
据我所知,这个错误可能是由DataImportHandler和SolrRequestHandler引起的,据说它是持有不同的类加载器.
每当我从示例中的start.jar应用程序启动Solr时(我认为它启动了一个Jetty服务器)它运行正常.
我的问题是:这真的是因为类加载器问题还是其他一些问题?而且,更重要的是:我该如何解决?
我按照@提到的步骤: http://wiki.apache.org/solr/DataImportHandler
我也尝试过stackoverflow的其他解决方案,但仍然无法正常工作.
问题是: 我每次运行时都配置了Delta-import处理程序; 它索引来自DB的所有记录.我在DB中有30条记录.每次我运行delta导入时,它都会索引所有30条记录.我只想将那些被更改/删除的内容编入索引.
任何有关此问题的快速帮助/指针/解决方案表示赞赏.
数据-config.xml中
<dataConfig>
<dataSource type="JdbcDataSource" name="ds-books" driver="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost/test" user="root" password=""/>
<document name="books">
<entity name="books" pk="id" query="select * from books" deltaImportQuery="SELECT * FROM books WHERE id = '${dataimporter.delta.id}'" deltaQuery="SELECT id FROM books WHERE last_modified > '${dataimporter.last_index_time}'" >
<field column="id" name="id" indexed="true" stored="true"/>
<field column="NAME" name="name" />
<field column="PRICE" name="price" />
<field column="last_modified" name="last_modified" />
</entity>
</document>
</dataConfig>
Run Code Online (Sandbox Code Playgroud)
我用来执行它的命令是:
http://localhost:8983/solr/dataimport?command=delta-import
Run Code Online (Sandbox Code Playgroud)
dataimport.properties文件:
5月10日星期五17:13:18 IST 2013
last_index_time = 2013-05-10 17 \:13 \:18
books.last_index_time = 2013-05-10 17 \:13 \:18 …
我是Solr的新手,我正在努力导入一些不包含ID字段的XML数据,尽管它是必需的,因为它表示我的schema.xml:
一个XML示例:
<results>
<estacions>
<estacio id="72400" nom="Aeroport"/>
<estacio id="79600" nom="Arenys de Mar"/>
...
</estacions>
</results>
Run Code Online (Sandbox Code Playgroud)
Schema.xml的:
<uniqueKey>id</uniqueKey>
Run Code Online (Sandbox Code Playgroud)
此时,我需要从http fetch导入这个xml,然后我使用DataimportHandler.这是我的data-config.xml
<dataConfig>
<dataSource type="URLDataSource" />
<document>
<entity name="renfe"
url="http://host_url/myexample.xml"
processor="XPathEntityProcessor"
forEach="/results/estacions/estacio"
transformer="script:generateCustomId">
<field column="idestacio" xpath="/results/estacions/estacio/@id" commonField="true" />
<field column="nomestacio" xpath="/results/estacions/estacio/@nom" commonField="true" />
</entity>
</document>
Run Code Online (Sandbox Code Playgroud)
然后,它似乎工作正常,但我收到以下错误:org.apache.solr.common.SolrException:[doc = null]缺少必填字段:id
这让我觉得我应该在导入时生成一个自动id,并使用data-config.xml,但是我没有看到如何做到这一点.
我应该怎么做?使用ScriptTransformer?任何想法都很感激
另一个问题:我可以在导入期间强制输入值吗?
例如:( <field column="site" value="estacions"/>
显然这不起作用)
Solr索引需要太长时间.我正在使用超过3000万条记录的mysql.我正在使用两级子查询.请建议我索引数据的最佳实践,以便我可以加快这个过程.
我已经在服务器上安装并配置了Solr4和tomcat6.它工作得很好,但是当我尝试构建DIH(数据导入处理程序)时,它给了我一个错误,我无法解决.
我将以下代码添加到我的solrconfig.xml文件中
<requestHandler name="/dataimport" class="org.apache.solr.handler.dataimport.DataImportHandler">
<lst name="defaults">
<str name="config">/path/to/data-config.xml</str>
</lst>
Run Code Online (Sandbox Code Playgroud)
我的data-config.xml文件如下所示
<dataConfig>
<dataSource type="FileDataSource" />
<document>
<entity name="f" processor="FileListEntityProcessor" baseDir="/path/to/basedirectory/toxmlfiles/" fileName=".*xml" recursive="true" rootEntity="false" dataSource="null">
<field column="plainText" name="text"/>
</entity>
</document>
Run Code Online (Sandbox Code Playgroud)
我点击localhost时在浏览器上遇到的错误:8080/solr /
我的错误日志中的错误是
SEVERE: Unable to create core: collection1
org.apache.solr.common.SolrException: RequestHandler init failure
at org.apache.solr.core.RequestHandlers.initHandlersFromConfig(RequestHandlers.java:168)
at org.apache.solr.core.SolrCore.<init>(SolrCore.java:657)
at org.apache.solr.core.SolrCore.<init>(SolrCore.java:566)
at org.apache.solr.core.CoreContainer.create(CoreContainer.java:850)
at org.apache.solr.core.CoreContainer.load(CoreContainer.java:534)
at org.apache.solr.core.CoreContainer.load(CoreContainer.java:356)
at org.apache.solr.core.CoreContainer$Initializer.initialize(CoreContainer.java:308)
at org.apache.solr.servlet.SolrDispatchFilter.init(SolrDispatchFilter.java:107)
at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:295)
at org.apache.catalina.core.ApplicationFilterConfig.setFilterDef(ApplicationFilterConfig.java:422)
at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:115)
at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:3838)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4488)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:526)
at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:637)
at org.apache.catalina.startup.HostConfig.deployDescriptors(HostConfig.java:563)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:498) …
Run Code Online (Sandbox Code Playgroud) dih ×11
solr ×11
solr4 ×3
apache ×1
geohashing ×1
geolocation ×1
indexing ×1
java ×1
jboss ×1
lucene ×1
mongodb ×1
solrcloud ×1
sql-server ×1