Search Solr MultiCore

I use Apache Solr to search. I use this to provide a personal user search. that is, each user has a separate Lucene physical index. So, for 10 users, I have 10 separate physical indexes on disk.

To support searches on these indexes, I plan to use the Solr MultiCore function . With the various articles I read about this, it seems like this will work.

Where am I really not sure when the solr search query receives the query, instead of sending a query to all multicore kernels, how do I query the kernel that this particular user index is connected to? Is this a configuration change or do I need to make code level changes?

i.e. I want to send a request to only one solr-core (based on userid). Is it possible?

UPDATE: Thus, according to one of the solutions, I can add multi-roots to the solrconfig.xml file, that is, during the start of solr I will need to specify the kernel (or in my case users). So now, if I want to add a new user index, I probably have to stop solr, edit its configuration, add this user kernel, and run solr again. Is there a way to dynamically add kernels to an executable instance of solr?

+4
source share
4 answers

Solr kernels are essentially multiple indexes that run in the same context on the application server. You can think of it as installing 1 war file for each user. Each core is separated by a name, so you must track for yourself which URL is valid for which user.

For instance,

http://host.com/solr/usercore1/select?q=test http://host.com/solr/usercore2/select?q=test

Based on config solr.xml:

 <solr persistent="true" sharedLib="lib"> <cores adminPath="/admin/cores"> <core name="usercore1" instanceDir="usercore1" /> <core name="usercore2" instanceDir="usercore1" /> </cores> </solr> 

... instead of sending a request to all multi-core cores ...

This approach is called sharding and is based on distributed search, which is a completely separate function that focuses on splitting one user index into multiple solr instances.

[EDIT] One approach to creating new kernels is solrj, which provides the CoreAdmin.createCore(..) routine. You can also do this using a manual HTTP request: /cores?action=CREATE&name=usercore3 ...

Solr can also dynamically update the configuration, if you have a script that edited the kernel configuration, these changes should also be matched.

+10
source

You can combine multicore with sharding through the following URL:

 http://localhost:8983/solr/core0/select?shards=localhost:8983/solr/core0,localhost:8983/solr/core1&q=*:* 
+7
source

Im using solrj.

First, create the kernels. I found 2 ways.

first way:

 SolrCore solrCore = coreContainer.create(new CoreDescriptor( coreContainer, coreName, ".")); coreContainer.register(solrCore, true); 

second way:

 SolrQuery solrQuery = new SolrQuery(); solrQuery.setParam(CommonParams.QT, "/admin/cores"); solrQuery.setParam( CoreAdminParams.ACTION, CoreAdminParams.CoreAdminAction.CREATE.name()); solrQuery.setParam( CoreAdminParams.NAME, name); solrQuery.setParam( CoreAdminParams.INSTANCE_DIR, "./" + name); solrQuery.setParam( CoreAdminParams.CONFIG, solrHomeRelativePath + solrConfigHomeRelativePath); solrQuery.setParam( CoreAdminParams.SCHEMA, solrHomeRelativePath + solrSchemaHomeRelativePath); solrQuery.setParam( CoreAdminParams.DATA_DIR, "."); solrServer.query(solrQuery); 

to request a specific kernel, which I just do:

 SolrServer solrServer = new EmbeddedSolrServer(coreContainer, coreName); 

and then fulfill my queries the way I usually do using solrj.

So, in your case, you just get the name associated with the user performing the search request. The coreContainer instance will be a common, but not an instance of SolrServer.

By the way, I'm doing something like you!

See you later.

+3
source

When you use mmulticore, you create a separate conf folder that contains a separate query and a schema and a way to get the results.

And when you click below url

 http://{your localhost}:8983/solr 

You will see a list of the kernels you created. and for each core you will need to create an index like this

 http://{your localhost}:8983/solr/{your_core_name1}/dataimport?command=full-import http://{your localhost}:8983/solr/{your_core_name2}/dataimport?command=full-import http://{your localhost}:8983/solr/{your_core_name3}/dataimport?command=full-import 

and after creating the index, you will have to refer to the kernel when performing such a search,

 http://{your localhost}:8983/solr/{your_core_name3}/select/?q=*:*&start=0&rows=100 
+1
source

Source: https://habr.com/ru/post/1342642/


All Articles