我正在尝试使用solr-node模块在node.js中使用构面搜索来搜索在solr 6.6.5上建立索引的文档。但是当我添加facet = on&facet.query =时:我从solr-node收到HTTP 400响应。
var client = new SolrNode({
host: 'localhost',
port: '8983',
core: 'IRF18P4',
protocol: 'http',
debugLevel: 'ERROR' // log4js debug level paramter
});
var delhiCount = client.query.q('*:*&facet.query=city:delhi&facet=on');
// Search documents using strQuery
client.search(delhiCount, function (err, result) {
if (err) {
console.log(err);
return;
}
console.log('Response:', result.response);
});
但是,如果我尝试打开终端上打印的相同URL,它将起作用。对这里可能出什么问题有任何想法吗?
PS C:\Users\aarti\OneDrive\Documents\IR\Project4\gentelella-master\gentelella-master> node index.js
[2018-12-02 19:16:02.533] [ERROR] sole-node - Body {
url:
'http://localhost:8983/solr/IRF18P4/select?q=*%3A*%26facet%3Don%26facet.query%3Dcity%3Adelhi&wt=json',
status: 400,
statusText: 'Bad Request',
headers:
Headers {
_headers:
{ 'cache-control': [Array],
pragma: [Array],
expires: [Array],
'last-modified': [Array],
etag: [Array],
'content-type': [Array],
connection: [Array] } },
ok: false,
body:
PassThrough {
_readableState:
ReadableState {
objectMode: false,
highWaterMark: 16384,
buffer: BufferList { head: [Object], tail: [Object], length: 1 },
length: 280,
pipes: null,
pipesCount: 0,
flowing: null,
ended: false,
endEmitted: false,
reading: true,
sync: false,
needReadable: true,
emittedReadable: true,
readableListening: false,
resumeScheduled: false,
emitClose: true,
destroyed: false,
defaultEncoding: 'utf8',
awaitDrain: 0,
readingMore: false,
decoder: null,
encoding: null },
readable: true,
_events:
{ prefinish: [Function: prefinish],
unpipe: [Function: onunpipe],
drain: [Function: pipeOnDrainFunctionResult],
error: [Function: onerror],
close: [Function],
finish: [Function] },
_eventsCount: 6,
_maxListeners: undefined,
_writableState:
WritableState {
objectMode: false,
highWaterMark: 16384,
finalCalled: false,
needDrain: false,
ending: false,
ended: false,
finished: false,
destroyed: false,
decodeStrings: true,
defaultEncoding: 'utf8',
length: 0,
writing: false,
corked: 0,
sync: false,
bufferProcessing: false,
onwrite: [Function: bound onwrite],
writecb: null,
writelen: 0,
bufferedRequest: null,
lastBufferedRequest: null,
pendingcb: 0,
prefinished: false,
errorEmitted: false,
emitClose: true,
bufferedRequestCount: 0,
corkedRequestsFree: [Object] },
writable: true,
allowHalfOpen: true,
_transformState:
{ afterTransform: [Function: bound afterTransform],
needTransform: true,
transforming: false,
writecb: null,
writechunk: null,
writeencoding: 'buffer' } },
bodyUsed: false,
size: 0,
timeout: 0,
_raw: [],
_abort: false }
Solr server error: 400
答案 0 :(得分:0)
您在输出中打印的URL错误。
http://localhost:8983/solr/IRF18P4/select?q=*%3A*%26facet%3Don%26facet.query%3Dcity%3Adelhi&wt=json
上面应该看起来像
http://localhost:8983/solr/IRF18P4/select?q=*:*&facet=on&facet.query=city:delhi&wt=json
您的代码应该是
var delhiCount = client.query
.q('*:*')
.addParams({
facet: 'true',
facet.query: "city:delhi"
wt: 'json',
});
有关更多帮助,请参考, 资源:https://www.npmjs.com/package/solr-node