如何绕过Elasticsearch 5.0中的有效负载

时间:2017-02-01 13:28:06

标签: node.js express elasticsearch

我正在将旧的Elasticsearch集群升级到Elasticsearch 5.0。

我注意到他们从Elasticsearch 5.0中删除了payload,这阻止我成功升级Elasticsearch。

我意识到payload在我的代码中多次出现。以下是我的代码段,其中包含payload

elasticClient.index({
  index: "users",
  type: "user",
  id: username,
  body: {
    name_suggest: {
      input: displayname
      payload: { "user_id": username }
    }
  }
}, function(error) {
  console.log(error);
});

我正在使用React.js(JSX)和Express.js在以下代码段中显示搜索结果。

return (
  <ul id="searchValue" key="wow">
    {result.options[0] ? <a href={"users/" + result.options[0].payload.user_id}><li style={{display: this.state.searchResults}} key={ result.options[0].payload.user_id }>{ result.options[0].text}</li></a> : null}
    {result.options[1] ? <a href={"users/" + result.options[1].payload.user_id}><li style={{display: this.state.searchResults}} key={ result.options[1].payload.user_id }>{ result.options[1].text}</li></a> : null}
    {result.options[2] ? <a href={"users/" + result.options[2].payload.user_id}><li style={{display: this.state.searchResults}} key={ result.options[2].payload.user_id}>{ result.options[2].text}</li></a> : null}
    {result.options[3] ? <a href={"users/" + result.options[3].payload.user_id}><li style={{display: this.state.searchResults}} key={ result.options[3].payload.user_id}>{ result.options[3].text}</li></a> : null}
    {result.options[4] ? <a href={"users/" + result.options[4].payload.user_id}><li style={{display: this.state.searchResults}} key={ result.options[4].payload.user_id}>{ result.options[4].text}</li></a> : null}
  </ul>
)

如您所见,我多次使用payload

在Elasticsearch 5.0中,如何在没有payload的情况下更新代码以使其正常工作?

1 个答案:

答案 0 :(得分:0)

我必须使用payload删除每一行,而使用_source代替here

例如:

return (
  <ul id="searchValue" key="wow">
    {result.options[0] ? <a href={"users/" + result.options[0]._source.name_suggest.input}><li style={{display: this.state.searchResults}} key={ result.options[0]._source.name_suggest.input}>{ result.options[0].text}</li></a> : null}
    {result.options[1] ? <a href={"users/" + result.options[1]._source.name_suggest.input}><li style={{display: this.state.searchResults}} key={ result.options[1]._source.name_suggest.input}>{ result.options[1].text}</li></a> : null}
    {result.options[2] ? <a href={"users/" + result.options[2]._source.name_suggest.input}><li style={{display: this.state.searchResults}} key={ result.options[2]._source.name_suggest.input}>{ result.options[2].text}</li></a> : null}
    {result.options[3] ? <a href={"users/" + result.options[3]._source.name_suggest.input}><li style={{display: this.state.searchResults}} key={ result.options[3]._source.name_suggest.input}>{ result.options[3].text}</li></a> : null}
    {result.options[4] ? <a href={"users/" + result.options[4]._source.name_suggest.input}><li style={{display: this.state.searchResults}} key={ result.options[4]._source.name_suggest.input}>{ result.options[4].text}</li></a> : null}
  </ul>
)

payload.user_id更改为_source.name_suggest.input

我还删除了行payload: { "user_id": username },因为在Elasticsearch 5.0中不需要它。