如何在 SolrJ 的查询中设置集合
How to set collection in query in SolrJ
我正在开发一个在 DSE 之上使用 SolrJ 进行搜索的系统。目前,我正在 Java 中使用 SolrJ 实现搜索功能。我使用基础 URL (http://localhost:PORT/solr) 创建了 SolrClient,并且我在请求查询
时尝试指定集合
client.query("collectionName", query);
但是,在我看来,SolrJ 忽略了集合,因为我收到以下错误:
/solr/update The requested resource is not available.
当我将集合添加到 SolrClient URL 而不是在查询函数中时,它工作正常。此解决方案阻止我使用单个客户端请求多个集合,因此我想使用第一个。有人遇到过这个吗?
编辑:
我也在 6.6 上检查过。还是一样。完整错误:
Error from server at http://localhost:8983/solr: Expected mime type
application/octet-stream but got text/html. Apache Tomcat/8.0.47 - Error
reportH1
{font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;}
H2
{font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;}
H3
{font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;}
BODY
{font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;}
B
{font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P
{font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A
{color : black;}A.name {color : black;}.line {height: 1px;
background-color: #525D76; border: none;}
HTTP Status 404 - /solr/update
type Status report
message
/solr/update
description The requested resource
is not available.
Apache
Tomcat/8.0.47
org.apache.solr.client.solrj.impl.HttpSolrClient$RemoteSolrException:
Error from server at http://localhost:8983/solr: Expected mime type
application/octet-stream but got text/html. Apache Tomcat/8.0.47 - Error
reportH1
{font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;}
H2
{font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;}
H3
{font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;}
BODY
{font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;}
B
{font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P
{font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A
{color : black;}A.name {color : black;}.line {height: 1px;
background-color: #525D76; border: none;}
HTTP Status 404 - /solr/update
type Status report
message
/solr/update
description The requested resource
is not available.
Apache
Tomcat/8.0.47
确实不鼓励使用 Solr HTTP API - 最好使用 CQL integration:
- 更新 HTTP API 在 DSE 6 中被完全删除,连同其他 APIs,如核心管理、查询删除等;
- 当您使用 CQL 时,DSE 搜索能够根据不同的统计信息(如索引状态等)更好地路由请求;
- 您可以使用与普通 CQL 查询相同的驱动程序;
- CQL syntax for DSE Search 非常灵活,允许创建非常复杂的查询,包括分面。
- ...
DSE 搜索文档中有很多使用示例。
嗯,这真的很奇怪 - 刚刚在我的测试环境中的 DSE 6.0.2 上测试过 - 对我的表来说工作得很好(使用标准 SolrJ 客户端 6.6.0):
<dependency>
<groupId>org.apache.solr</groupId>
<artifactId>solr-solrj</artifactId>
<version>6.6.0</version>
</dependency>
代码:
public static void main(String[] args) throws SolrServerException, IOException {
String url = "http://192.168.0.10:8983/solr";
SolrClient client = new HttpSolrClient.Builder(url).build();
SolrQuery query = new SolrQuery();
query.setQuery("*:*");
query.addFilterQuery("user:\"krystina.morissette\"");
query.setRows(10);
QueryResponse response = client.query("gatling.user_tokens", query);
SolrDocumentList list = response.getResults();
System.out.println("Num found=" + list.getNumFound());
for (SolrDocument doc: list) {
System.out.println(doc);
}
}
给我以下信息:
Num found=4
SolrDocument{_uniqueKey=["krystina.morissette","36c8a420-b91f-477c-88b4-59ca8c59c69e"], expires=Wed Jul 25 11:42:13 CEST 2018, created=Wed Jul 25 11:12:13 CEST 2018, id=36c8a420-b91f-477c-88b4-59ca8c59c69e, user=krystina.morissette, nonce=-2015059461}
SolrDocument{_uniqueKey=["krystina.morissette","9ab1c4be-6764-429b-baeb-923ae7139aa9"], expires=Wed Jul 25 11:45:34 CEST 2018, created=Wed Jul 25 11:15:34 CEST 2018, id=9ab1c4be-6764-429b-baeb-923ae7139aa9, user=krystina.morissette, nonce=-239263702}
SolrDocument{_uniqueKey=["krystina.morissette","8bff6a10-06b4-4473-876d-8380af0568cc"], expires=Wed Jul 25 11:47:48 CEST 2018, created=Wed Jul 25 11:17:48 CEST 2018, id=8bff6a10-06b4-4473-876d-8380af0568cc, user=krystina.morissette, nonce=-658876494}
SolrDocument{_uniqueKey=["krystina.morissette","3f011a59-5bdc-4b7e-b465-d83c29cb333f"], expires=Wed Jul 25 11:49:12 CEST 2018, created=Wed Jul 25 11:19:12 CEST 2018, id=3f011a59-5bdc-4b7e-b465-d83c29cb333f, user=krystina.morissette, nonce=-583776467}
我正在开发一个在 DSE 之上使用 SolrJ 进行搜索的系统。目前,我正在 Java 中使用 SolrJ 实现搜索功能。我使用基础 URL (http://localhost:PORT/solr) 创建了 SolrClient,并且我在请求查询
时尝试指定集合client.query("collectionName", query);
但是,在我看来,SolrJ 忽略了集合,因为我收到以下错误:
/solr/update The requested resource is not available.
当我将集合添加到 SolrClient URL 而不是在查询函数中时,它工作正常。此解决方案阻止我使用单个客户端请求多个集合,因此我想使用第一个。有人遇到过这个吗?
编辑: 我也在 6.6 上检查过。还是一样。完整错误:
Error from server at http://localhost:8983/solr: Expected mime type application/octet-stream but got text/html. Apache Tomcat/8.0.47 - Error reportH1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}.line {height: 1px; background-color: #525D76; border: none;}
HTTP Status 404 - /solr/update
type Status report
message /solr/update
description The requested resource is not available.
Apache Tomcat/8.0.47
org.apache.solr.client.solrj.impl.HttpSolrClient$RemoteSolrException: Error from server at http://localhost:8983/solr: Expected mime type application/octet-stream but got text/html. Apache Tomcat/8.0.47 - Error reportH1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}.line {height: 1px; background-color: #525D76; border: none;}HTTP Status 404 - /solr/update
type Status report
message /solr/update
description The requested resource is not available.
Apache Tomcat/8.0.47
确实不鼓励使用 Solr HTTP API - 最好使用 CQL integration:
- 更新 HTTP API 在 DSE 6 中被完全删除,连同其他 APIs,如核心管理、查询删除等;
- 当您使用 CQL 时,DSE 搜索能够根据不同的统计信息(如索引状态等)更好地路由请求;
- 您可以使用与普通 CQL 查询相同的驱动程序;
- CQL syntax for DSE Search 非常灵活,允许创建非常复杂的查询,包括分面。
- ...
DSE 搜索文档中有很多使用示例。
嗯,这真的很奇怪 - 刚刚在我的测试环境中的 DSE 6.0.2 上测试过 - 对我的表来说工作得很好(使用标准 SolrJ 客户端 6.6.0):
<dependency>
<groupId>org.apache.solr</groupId>
<artifactId>solr-solrj</artifactId>
<version>6.6.0</version>
</dependency>
代码:
public static void main(String[] args) throws SolrServerException, IOException {
String url = "http://192.168.0.10:8983/solr";
SolrClient client = new HttpSolrClient.Builder(url).build();
SolrQuery query = new SolrQuery();
query.setQuery("*:*");
query.addFilterQuery("user:\"krystina.morissette\"");
query.setRows(10);
QueryResponse response = client.query("gatling.user_tokens", query);
SolrDocumentList list = response.getResults();
System.out.println("Num found=" + list.getNumFound());
for (SolrDocument doc: list) {
System.out.println(doc);
}
}
给我以下信息:
Num found=4
SolrDocument{_uniqueKey=["krystina.morissette","36c8a420-b91f-477c-88b4-59ca8c59c69e"], expires=Wed Jul 25 11:42:13 CEST 2018, created=Wed Jul 25 11:12:13 CEST 2018, id=36c8a420-b91f-477c-88b4-59ca8c59c69e, user=krystina.morissette, nonce=-2015059461}
SolrDocument{_uniqueKey=["krystina.morissette","9ab1c4be-6764-429b-baeb-923ae7139aa9"], expires=Wed Jul 25 11:45:34 CEST 2018, created=Wed Jul 25 11:15:34 CEST 2018, id=9ab1c4be-6764-429b-baeb-923ae7139aa9, user=krystina.morissette, nonce=-239263702}
SolrDocument{_uniqueKey=["krystina.morissette","8bff6a10-06b4-4473-876d-8380af0568cc"], expires=Wed Jul 25 11:47:48 CEST 2018, created=Wed Jul 25 11:17:48 CEST 2018, id=8bff6a10-06b4-4473-876d-8380af0568cc, user=krystina.morissette, nonce=-658876494}
SolrDocument{_uniqueKey=["krystina.morissette","3f011a59-5bdc-4b7e-b465-d83c29cb333f"], expires=Wed Jul 25 11:49:12 CEST 2018, created=Wed Jul 25 11:19:12 CEST 2018, id=3f011a59-5bdc-4b7e-b465-d83c29cb333f, user=krystina.morissette, nonce=-583776467}