[英]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。 還是一樣。 完整錯誤:
來自服務器的錯誤,位於http:// localhost:8983 / solr :預期的mime類型為application / octet-stream,但獲得了text / html。 Apache Tomcat / 8.0.47-錯誤報告H1 {font-family:Tahoma,Arial,sans-serif; color:white; background-color:#525D76; font-size:22px;} H2 {font-family:Tahoma,Arial, sans-serif;顏色:白色;背景顏色:#525D76;字體大小:16px;} H3 {字體系列:Tahoma,Arial,sans-serif;顏色:白色;背景顏色:#525D76;字體大小: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 {字體家族:Tahoma,Arial,sans-serif;背景:白色;顏色:黑色;字體大小:12px;} A {顏色:黑色;} A.name {顏色:黑色;} .line {height:1px; 背景顏色:#525D76; 邊框:無;}
HTTP狀態404-/ solr / update
類型狀態報告
消息 / solr / update
描述所請求的資源不可用。
Apache Tomcat / 8.0.47
org.apache.solr.client.solrj.impl.HttpSolrClient $ RemoteSolrException:來自http:// localhost:8983 / solr的服務器錯誤:預期的mime類型為application / octet-stream,但有text / html。 Apache Tomcat / 8.0.47-錯誤報告H1 {font-family:Tahoma,Arial,sans-serif; color:white; background-color:#525D76; font-size:22px;} H2 {font-family:Tahoma,Arial, sans-serif;顏色:白色;背景顏色:#525D76;字體大小:16px;} H3 {字體系列:Tahoma,Arial,sans-serif;顏色:白色;背景顏色:#525D76;字體大小:14px;} BODY {字體家族:Tahoma,Arial,sans-serif;顏色:黑色;背景色:白色;} B {font-family:Tahoma,Arial,sans-serif; color:white; background-color :#525D76;} P {字體家族:Tahoma,Arial,sans-serif;背景:白色;顏色:黑色;字體大小:12px;} A {顏色:黑色;} A.name {顏色:黑色;} .line {height:1px; 背景顏色:#525D76; 邊框:無;}HTTP狀態404-/ solr / update
類型狀態報告
消息 / solr / update
描述所請求的資源不可用。
Apache Tomcat / 8.0.47
嗯,這真的很奇怪-剛剛在我的測試環境中在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}
實在不建議使用Solr HTTP API-最好使用CQL集成 :
DSE搜索文檔中有許多使用示例。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.