参考:https://www.elastic.co/guide/en/elasticsearch/reference/current/binary.html
-------------------------------
插入脚本如下: 其中nc为要插入的二进制文件
#!/bin/bash a=`xxd -p nc` es_url="192.168.2.10:9201" a=`echo ${a}|sed 's/\n//g'` curl -X PUT "${es_url}/my_index?pretty" -H 'Content-Type: application/json' -d' { "mappings": { "properties": { "name": { "type": "text" }, "blob": { "type": "binary" } } } } ' curl -X PUT "${es_url}/my_index/_doc/1?pretty" -H 'Content-Type: application/json' -d" { \"name\": \"Some binary blob\", \"blob\": \"${a}\" } "
查询脚本如下: 其中a_search为读出的二进制文件
#!/bin/bash a=`curl "192.168.2.10:9201/my_index/_doc/_search?"|jq ".hits.hits[0]._source.blob"` echo ${a}|xxd -r -p >a_search
-------------------------------
Binary datatypeedit
The
binary
type accepts a binary value as a Base64 encoded string. The field is not stored by default and is not searchable:PUT my_index { "mappings": { "properties": { "name": { "type": "text" }, "blob": { "type": "binary" } } } } PUT my_index/_doc/1 { "name": "Some binary blob", "blob": "U29tZSBiaW5hcnkgYmxvYg==" }
没有评论:
发表评论