弹性搜索分析器错误

时间:2015-04-12 21:19:47

标签: javascript node.js search elasticsearch

我正在尝试在Javascript中构建以下搜索调用而没有运气,下面的工作正常,所以我知道我的索引在ES中设置正确。

GET /teachersx9/teacher/_search
   {
     "query": {
     "bool": {
       "must": [
          { "match_all": {}},
          {
            "nested": {
               "path": "langs",
               "score_mode": "max", 
               "query": {
                   "bool": {
                      "must": [
                         { "match": { "languagename": "Afrikaans"}}
                    ]
         }}}}
     ]
 }}}

但是,尝试使用以下命令在我的服务器上创建查询时

app.get('/search', function(req, res) {

var term = req.query.term;//req.param('term');
var urlPath = 'https:.../teachersx9/teacher/_search';

//var obj = {};
var query = {};
query.bool = {};

var match_all = {};
var nested = {path:"langs", score_mode:"max"};
nested.query = {};
nested.query.bool = {};
nested.query.bool.must = [{match: {languagename:term}}];
query.bool.must = [{match_all:match_all}, {nested:nested}]; 

console.log(query);

request.post({
  url: urlPath,
  json: true, 
  body: query
}, function(error, response, body){
    if (!error && response.statusCode == 200) {

        console.log(body);
        res.send(body);
    } else {
        console.log(body);
        res.send(response);
    }
   });

 });

错误我从ES回来作为回复的一部分:

"statusCode": 400,
"body": {
"error": "SearchPhaseExecutionException[Failed to execute phase [query_fetch], all shards failed; shardFailures {[FMwFQZmkIAfOE7X48Q][teachersx9][0]: RemoteTransportException[[Quentin Quire][inet[/172.31.7.165:9300]][indices:data/read/search[phase/query+fetch]]]; nested: SearchParseException[[teachersx9][0]: from[-1],size[-1]: Parse Failure [Failed to parse source [{\"bool\":{\"must\":[{\"match_all\":{}},{\"nested\":{\"path\":\"langs\",\"score_mode\":\"max\",\"query\":{\"bool\":{\"must\":[{\"match\":{\"languagename\":\"Italian\"}}]}}}}]}}]]]; nested: SearchParseException[[teachersx9][0]: from[-1],size[-1]: Parse Failure [No parser for element [bool]]]; }]",
"status": 400
},

1 个答案:

答案 0 :(得分:0)

bool不是Elastic query DSL中的有效顶级构造。您需要将其包装在query

var body = { query: query }

request.post({
  url: urlPath,
  json: true, 
  body: body
})