如何从搜索查询中将数据插入弹性搜索

时间:2017-11-16 05:45:13

标签: elasticsearch

我尝试将一些数据从一个弹性数据库复制到另一个elasticsearch数据库,有没有办法从查询结果中插入数据?

结果示例:

        import React, { Component } from 'react';

    const urlForUsername = cryptocoin => `https://api.coinmarketcap.com/v1/ticker/${cryptocoin}/`

    class CryptoItem extends Component {

        constructor(props){
            super(props)
            this.state = {
                requestFailed: false
            }
        }

        componentDidMount(){
            fetch(urlForUsername(this.props.cryptocoin))
            .then(response =>{
                if(!response.ok){
                    throw Error("Network request failed")
                }
                return response
            })
            .then(d => d.json())
            .then(d => {
                this.setState({
                    cryptoData: d[0]
                })
            },() => {
                this.setState({
                    requestFailed: true
                })
            })
        }


        render() {
            if(this.state.requestFailed) return <p>Failed...</p>
            if(!this.state.cryptoData) return <p>Loading...</p>

            return(    
                <ul className="CryptoItem" data-sort={ `${this.state.cryptoData.percent_change_24h}` } id={ `${this.state.cryptoData.symbol}PriceChangeID` }>
                    <li>
                        {this.state.cryptoData.name}:
                    </li>
                    <li>
                        $ <span id={ `${this.state.cryptoData.symbol}Price` }>{this.state.cryptoData.price_usd}</span>
                    </li>
                    <li className="PreCentChange">
                        <span id={ `${this.state.cryptoData.symbol}PriceChange` }>{this.state.cryptoData.percent_change_24h}</span><b>%</b>
                    </li>
                </ul>
            );
        }
    }
    export default CryptoItem;

在每个db映射中都是等于。

1 个答案:

答案 0 :(得分:0)

我分叉一些项目,为elasticsearch制作批量数据,json-to-es-bulk

我与5.6 es版本的兼容性,您可以在2种变体中使用它:

`node index.js -f inputdata.json --index newIndexName --type newIndexType --rewrite true`

`node index.js -f inputdata.json --index --type --rewrite false`

运行后,您将看到一个文件request-data.txt,只需使用它即可 POST /_bulk [request-data.txt content]

输入数据json文件必须包含一系列搜索命中,如下所示:

[ { "_index": "oldIndexName", "_type": "oldIndexName", "_id": "SOME_ID-HiTfm", "_score": 1, "_source": { "orderNumber": "2984", "refId": "SOME_VALUE" } }, ... ]