GET fs_job_2024/_mapping
"filename": {
"type": "text",
"store": true,
"fields": {
"keyword": {
"type": "keyword"
}
},
"analyzer": "ik_smart"
},
"filesize": {
"type": "long"
},
"indexed_chars": {
"type": "long"
},
POST fs_job_2024/_search
{
"_source": [
"file.filesize"
],
"query": {
"bool": {
"must": [
{
"exists": {
"field": "file.filesize"
}
}
]
}
}
}
echo "This is my text" > test.txt
curl -F "file=@test.txt" "http://127.0.0.1:8080/fscrawler/_document"
echo "This is my text" > test.txt
curl -F "file=@test.txt" \
-F "tags={\"file\":{\"filesize\":$(ls -l test.txt | awk '{print $5}')}}" \
"http://127.0.0.1:8080/fscrawler/_document"
# 获取文件大小
file.seek( 0, os.SEEK_END )
file_size = file.tell()
file.seek( 0 ) # 重置文件指针
# 打印文件大小,用于调试
print( "File size:", file_size )
# 构建文件上传部分
files = {'file': (
file.filename, file, 'application/vnd.openxmlformats-officedocument.wordprocessingml.document')}
# 构建 tags 部分,包含文件大小等信息
tags = {'file': {'filesize': file_size}}
# 发送文件和表单数据到指定地址
response = requests.post(
FS_WEB_ADDRESS,
files=files,
data={'tags': json.dumps( tags )}, # 使用 json.dumps 将字典转换为 JSON 字符串
timeout=10
)


更短时间更快习得更多干货!
和全球 超2000+ Elastic 爱好者一起精进!
elastic6.cn——ElasticStack进阶助手

原文作者:铭毅天下Elasticsearch;如有侵权,请联系管理员删除。