从shell脚本调用弹性搜索索引pdf文档 [英] Call Elastic search from shell script for indexing pdf document

查看:251
本文介绍了从shell脚本调用弹性搜索索引pdf文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我安装了springsearch 5.0.1和相应的摄取附件。试用索引pdf文档从shell脚本如下

 #!/ bin / ksh 
var = $(base64 file_name。 pdf)

var1 = $(curl -XPUT'http:// localhost:9200 / my_index4 / my_type / my_id?pipeline = attachment& pretty'-d'{data:$ var}' )
echo $ var1






 我的错误为
{error:{root_cause:[{type:exception,reason:
java.lang.IllegalArgumentException: ElasticsearchParseException [在字段
[data]中解析文档时出错];嵌套:IllegalArgumentException [Illegal base64 character 24];,
header:{processor_type:attachment}}]

任何人都可以帮忙解决上述问题...不知道我是否传递无效的base64字符?



请注意,当我通过这个,它的作品!

  var1 = $(curl -XPUT'http:// localhost:9200 / my_index4 / my_type / my_id?美元'
-d'{data:e1xydGYxXGFuc2kNCkxvcmVtIGlwc3VtIGRvbG9yIHNpdCBhbWV0DQpccGFyIH0 =}')


解决方案

我猜这个问题必须在shell中扩展单引号中的变量,需要双引号来扩展它。即



更改 -d'{data:$ var}'



  -d'{data:'$(base64 file_name.pdf) $

直接传递 base64 流。



(或)

  -d'{ data:'$ var'''

更多关于引用和变量的 ksh here


I installed elasticsearch 5.0.1 and corresponding ingest attachment. Tried indexing pdf document from shell script as below

#!/bin/ksh  
var=$(base64 file_name.pdf)

var1=$(curl -XPUT 'http://localhost:9200/my_index4/my_type/my_id?pipeline=attachment&pretty' -d' { "data" : $var }')
echo $var1


I got error as 
{ "error" : { "root_cause" : [ { "type" : "exception", "reason" : 
"java.lang.IllegalArgumentException: ElasticsearchParseException[Error parsing document in field 
[data]]; nested: IllegalArgumentException[Illegal base64 character 24];",
 "header" : { "processor_type" : "attachment" } } ]...

Can anyone please help on resolving the above issue ... Not sure whether I am passing invalid base64 character ?

Please note that when I pass like this, It works !

var1=$(curl -XPUT 'http://localhost:9200/my_index4/my_type/my_id?pipeline=attachment&pretty'
-d' { "data" : "e1xydGYxXGFuc2kNCkxvcmVtIGlwc3VtIGRvbG9yIHNpdCBhbWV0DQpccGFyIH0=" }')

解决方案

I guess the issue has to shell not expanding the variables within single-quotes, you need to double-quote to expand it. i.e.

change -d' { "data" : $var }'

to

-d '{"data" : "'"$(base64 file_name.pdf)"'"}'  

directly to pass the base64 stream.

(or)

-d '{"data" : "'"$var"'"}'

More about quoting and variables in ksh here.

这篇关于从shell脚本调用弹性搜索索引pdf文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆