Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/440.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 $http PUT请求中的设置处理器未保存正确的数据_Javascript_Html_Angularjs_<img Src="//i.stack.imgur.com/RUiNP.png" Height="16" Width="18" Alt="" Class="sponsor Tag Img">elasticsearch - Fatal编程技术网 elasticsearch,Javascript,Html,Angularjs,elasticsearch" /> elasticsearch,Javascript,Html,Angularjs,elasticsearch" />

Javascript $http PUT请求中的设置处理器未保存正确的数据

Javascript $http PUT请求中的设置处理器未保存正确的数据,javascript,html,angularjs,elasticsearch,Javascript,Html,Angularjs,elasticsearch,对javascript和angular相对较新。我正在使用elasticsearch实例接收/索引不同的文件。webapp应该能够允许用户上传多个文件,然后使用摄取处理器处理这些文件并将其编入索引。我正在使用angular-base64-upload提取base64数据。以下是我到目前为止所做的尝试 html: <div ng-switch-when="upload"> ... <input type="file" ng-model="obj.files" name="

对javascript和angular相对较新。我正在使用elasticsearch实例接收/索引不同的文件。webapp应该能够允许用户上传多个文件,然后使用摄取处理器处理这些文件并将其编入索引。我正在使用angular-base64-upload提取base64数据。以下是我到目前为止所做的尝试

html:

<div ng-switch-when="upload">
...
    <input type="file" ng-model="obj.files" name="files" 
           base-sixty-four-input multiple>
    ...
    <div ng-show="obj.files.length != 0">
       <button class="btn btn-primary" type="submit" ng-click="ingest()">
           Index All {{obj.files.length}} Files
       </button> <br><br>
    </div>
</div>
控制台日志记录仅用于调试目的

我遇到的问题是,当elastic将文件存储在适当的_id(在我的情况下是文件名)下时,它没有存储适当的
字段:filename
。例如,如果我上传两个名为hello.txt和world.txt的文件,ES将以
hello
world
作为各自的
\u id
存储这两个文件,但
filename
字段经常交换,或者通常不正确。我已经多次运行该代码以查看是否存在模式,但似乎真的找不到模式

console.log
s显示
fname
是第一个
http
之前、之后和第二个
http
之后的正确文件名,这就是为什么我对
set
处理器没有正确存储它感到困惑的原因


我可能没有很好地解释这个问题,因为它有点复杂。如果有什么需要解释的,请告诉我。谢谢

请显示
base六十四input
指令的代码。我被告知ng switch创建自己的作用域,因此如果我希望$scope.files(在本例中)接收输入,我需要添加$parent。这是错误的吗?我刚刚意识到我没有显示这个代码嵌套在ng开关中。。。为清晰起见进行了编辑。循环中的两个PUT操作可能需要链接,而不是并行执行。事实上,所有PUT操作可能都需要顺序链接。此外,由于代码对每个文件执行单独的PUT操作,因此以二进制形式发送文件比将文件转换为更有效。Base64编码为PUT请求添加了33%以上的数据,并且已知会使带有大文件的浏览器崩溃。我已编辑代码以修复$parent问题,并尝试链接PUT请求(不确定是否正确执行)。原来的问题依然存在。另外,我的印象是elasticsearch只接受b64编码的数据。这是我不传递二进制数据的唯一原因。
//Ingesting multiple files
$scope.obj = {files: []};
$scope.ingest = function () {

    $scope.obj.files.forEach(function (file){
        var fname = file.filename.replace(/\.[^/.]+$/, "");
        var fdata = file.base64;
        //Creating the pipeline
        console.log('filename is: ' + fname);
        $http({
            url: 'http://192.168.100.30:9200/_ingest/pipeline/attachment',
            method: "PUT",
            data: {
                 "description" : "Indexing files",
                     "processors" : [
                       {
                         "set" : {
                           "field" : "filename",
                           "value" : fname
                         },
                         "attachment" : {
                           "field" : "data"
                         }
                       }
                     ]
            }
        })
        .then(function(allowed){
                //Indexing the document
                $http({
                    url: 'http://192.168.100.30:9200/my_index4/my_type/'+fname+'?pipeline=attachment', //unique ID for every document, ensures that there are no overlaps
                    method: "PUT",
                    data: {
                        "data": fdata
                    }
                })

        })
    })
}