请求包含无法识别的参数:[type]弹性搜索,同时请求获取建议

时间:2017-09-02 10:52:58

标签: node.js express elasticsearch

我是节点js + express中弹性搜索的新手,我很难在弹性搜索中获得建议。

下面我已经完成了对es建议的请求。

1)我创建了es index(name-“movies”)和type(“movie”)以及index的映射。

索引是:

return elasticClient.indices.create({
      index:"movies",
      body : {
        "settings" : {
          "index" : {
              "number_of_shards" : 5,
              "number_of_replicas" : 2
          }
        }
      }
    });
  }

映射是:

createMovieMapping:function(){
    return elasticClient.indices.putMapping({
      index:"movies",
      type:"movie",
      body:{
          properties:{
            movieName : {type:"string"},
            suggest:{
              type:"completion",
              analyzer:"simple",
              search_analyzer:"simple",
              payloads:true
            }
          }
        }
    })
  }

2)将我的数据库中的一些数据推送到es索引类型为“movie”的“电影”。

在索引中添加数据的功能:

addDataToMovieEsIndex:function(document){
    return elasticClient.index({
      index:"movies",
      type:"movie",
      id:document._id, // for preventing duplicate insertion
      body:{
        movieName:document.movie_name,
        suggest:{
          input : document.movie_name.split(" "),
          output : document.movie_name,
          payload : document
        }
      }
    })
  }

3)现在我正在尝试使用以下创建的函数获得建议结果 -

getMovieSuggestion: function(input){
    elasticClient.suggest({
      index:"movies",
      type:"movie",
      body : {
        moviesuggest:{
          text: input,
          completion:{
            field : "suggest",
            fuzzy : true
          }
        }
      }
    },function(err,resp){
      if(resp){
        console.log('response ',resp)
      }
      if(err){
        console.log('error ',err);        
      }      
    })
  }

但是我在获取获取电影结果建议的请求时遇到了错误。

{ Error: [illegal_argument_exception] request [/movies/_suggest] contains unrecognized parameter: [type]
    at respond (/Users/siyaram.malav/malav/my_apps/movie-info-app/node_modules/elasticsearch/src/lib/transport.js:307:15)
    at checkRespForFailure (/Users/siyaram.malav/malav/my_apps/movie-info-app/node_modules/elasticsearch/src/lib/transport.js:266:7)
    at HttpConnector.<anonymous> (/Users/siyaram.malav/malav/my_apps/movie-info-app/node_modules/elasticsearch/src/lib/connectors/http.js:159:7)
    at IncomingMessage.bound (/Users/siyaram.malav/malav/my_apps/movie-info-app/node_modules/lodash/dist/lodash.js:729:21)
    at emitNone (events.js:91:20)
    at IncomingMessage.emit (events.js:185:7)
    at endReadableNT (_stream_readable.js:974:12)
    at _combinedTickCallback (internal/process/next_tick.js:80:11)
    at process._tickCallback (internal/process/next_tick.js:104:9)
  status: 400,
  displayName: 'BadRequest',
  message: '[illegal_argument_exception] request [/movies/_suggest] contains unrecognized parameter: [type]',
  path: '/movies/_suggest',
  query: { type: 'movie' },
  body: '{"moviesuggest":{"text":"Sultan","completion":{"field":"suggest","fuzzy":true}}}',

注意:我尝试从getMovieSuggestion函数中删除类型:“movie”,然后它会出现以下错误:

Error: [illegal_argument_exception] no mapping found for field [suggest]

任何帮助将不胜感激。 感谢。

1 个答案:

答案 0 :(得分:1)

你不应该使用

import seaborn
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-1-085c0287ecb5> in <module>()
----> 1 import seaborn

ImportError: No module named seaborn

在对elasticClient.suggest的调用中。

请参阅此处以供参考,https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/api-reference.html#api-suggest

应该是:

type:"movie"

此外,根据OP使用ES 5.5,ES JS API仍然使用_suggest端点,该端点已弃用。使用带有适当参数的_search端点的工作方式如注释中所示。