2017-02-01 6 views
1

私は古いElasticsearchクラスターをElasticsearch 5.0にアップグレードするプロセスに入っています。Elasticsearch 5.0でペイロードを回避する方法

Elasticsearch 5.0から​​が削除されていることに気付き、Elasticsearchを正常にアップグレードできなくなっています。

私は​​が自分のコードに何度も現れることに気付きました。以下は、​​を含むコードスニペットです。

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> 
) 

ご覧のとおり、私は​​を何回も使用します。

Elasticsearch 5.0では、​​を使用しないでコードを更新する必要がありますか?

答えて

0

​​ですべての行を削除し、hereの代わりに_sourceを使用する必要がありました。例えば

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では必須ではないためです。

関連する問題