elasticsearch,Reactjs,elasticsearch" /> elasticsearch,Reactjs,elasticsearch" />

Reactjs ElasticSearch JS和React代码中的简单查询

Reactjs ElasticSearch JS和React代码中的简单查询,reactjs,elasticsearch,Reactjs,elasticsearch,这是我为从React应用程序获取数据而创建的。现在我想把所有的项目(本例中只有一个)放到JS对象中,这样我就可以在我的webpge上映射数据。如何合并查询和代码以创建表示ES查询数据的简单数据对象 componentWillMount() { var that = this; client.search({ index: 'products' }).then(function (elasticResponse) { var hits = elasticResponse.hits.

这是我为从React应用程序获取数据而创建的。现在我想把所有的项目(本例中只有一个)放到JS对象中,这样我就可以在我的webpge上映射数据。如何合并查询和代码以创建表示ES查询数据的简单数据对象

componentWillMount() {
var that = this;
client.search({
    index: 'products'
}).then(function (elasticResponse) {
    var hits = elasticResponse.hits.hits;

    that.setState({
        items: hits.map((hit) => ({
            name: hit._source.name,
            description: hit._source.description,
            imgUrl: hit._source.imgUrl,
            price: hit._source.price
        }))

    });

}, function (error) {
    console.trace(error.message);
});
}

这是我放在ES里的唯一一个项目
{
“_索引”:“产品”,
“_类型”:“产品”,
“_id”:“1”,
“_分数”:1,
“_来源”:{
“img”:http://writingexercises.co.uk/images2/randomimage/anchors.jpg",
“标题”:“早餐”,
“作者”:“jill111”,
“价格”:100
}
}