Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/40.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Elasticsearch索引数据在查询中给出错误结果_Javascript_Node.js_Reactjs_<img Src="//i.stack.imgur.com/RUiNP.png" Height="16" Width="18" Alt="" Class="sponsor Tag Img">elasticsearch - Fatal编程技术网 elasticsearch,Javascript,Node.js,Reactjs,elasticsearch" /> elasticsearch,Javascript,Node.js,Reactjs,elasticsearch" />

Javascript Elasticsearch索引数据在查询中给出错误结果

Javascript Elasticsearch索引数据在查询中给出错误结果,javascript,node.js,reactjs,elasticsearch,Javascript,Node.js,Reactjs,elasticsearch,我正在尝试使用Elasticsearch为我的react web应用程序创建全文搜索,但它不会返回所有查询结果。我认为我在批量方法中犯了一些错误,但我无法理解我做错了什么。 我的代码是: // Declare variable to contain body of JSON data for loading to ElasticSearch let br = []; // Function to create body for loading to E

我正在尝试使用Elasticsearch为我的react web应用程序创建全文搜索,但它不会返回所有查询结果。我认为我在批量方法中犯了一些错误,但我无法理解我做错了什么。 我的代码是:

// Declare variable to contain body of JSON data for loading to ElasticSearch

                    let br = [];

// Function to create body for loading to ElasticSearch
                    function create_bulk (bulk_request) {
                        let obj;

                        for (let i = 0; i < res.length; i++) {
                            obj = res[i];
                            // Insert header of record
                            bulk_request.push({index: {_index: 'tweet', _type: 'tweet', _id: i+1}});
                            bulk_request.push(obj);
                        }
                        return bulk_request;
                    }

// Call function to get body for loading
                    create_bulk(br);

// Standard function of ElasticSearch to use bulk command
                    client.bulk(
                        {
                            body : br
                        }, function (err, resp) {
                            console.log(err);
                        });

                    client.search({
                        index: 'tweet',
                        type: 'tweet',
                        body: {
                            query: {
                                match: {"text" : "new york" }
                            },
                        }
                    },function (error, response,status) {
                        if (error){
                            console.log("search error: "+error)
                        }
                        else {
                            console.log("--- Response ---");
                            console.log(response);
                            console.log("--- Hits ---");
                            response.hits.hits.forEach(function(hit){
                                console.log(hit);
                            })
                        }
                    });

在批量调用和搜索调用之间,需要调用refresh以确保所有索引数据都可用于搜索

                client.bulk(
                    {
                        refresh: true,            <--- add this
                        body : br
                    }, function (err, resp) {
                        console.log(err);

                        client.search({...})      <--- and make your search call only when the bulk returns

                    });
client.bulk(
{

refresh:是的,在批量调用和搜索调用之间,您需要调用refresh以确保所有索引数据都可用于搜索。我该如何做?@Val它索引良好,因为它返回了10个结果,这是我猜想的限制。如果您从节点了解该限制,请告诉我如何更改该限制?我尝试了更改大小后,它将返回所有结果。是的,只需在您的搜索呼叫中添加
size:100
。谢谢,有没有办法包括所有搜索?如果没有,我将使用一些巨大的数字。科尔,很高兴这有帮助!
                client.bulk(
                    {
                        refresh: true,            <--- add this
                        body : br
                    }, function (err, resp) {
                        console.log(err);

                        client.search({...})      <--- and make your search call only when the bulk returns

                    });