我有一个装满了上千份文件的桶。我如何搜索水桶?


当前回答

S3没有原生的“搜索此桶”,因为实际内容是未知的-此外,由于S3是基于键/值的,因此没有原生的方法可以一次访问多个节点,而更传统的数据存储提供了一个(SELECT * FROM…(在SQL模型中)。

您需要做的是执行ListBucket以获得bucket中对象的列表,然后遍历每个项,执行您实现的自定义操作—这就是您的搜索。

其他回答

看一下这个文档:http://docs.aws.amazon.com/AWSSDKforPHP/latest/index.html#m=amazons3/get_object_list

您可以使用perl兼容正则表达式(PCRE)来筛选名称。

2018 - 07年现状: 亚马逊有本地sql像搜索csv和json文件!

https://aws.amazon.com/blogs/developer/introducing-support-for-amazon-s3-select-in-the-aws-sdk-for-javascript/

虽然不是AWS的原生服务,但有Mixpeek,它在S3文件上运行文本提取,如Tika、Tesseract和ImageAI,然后将它们放在Lucene索引中,使它们可搜索。

在这里查看文档

积分如下:

Download the module: https://github.com/mixpeek/mixpeek-python Import the module and your API keys: from mixpeek import Mixpeek, S3 from config import mixpeek_api_key, aws Instantiate the S3 class (which uses boto3 and requests): s3 = S3( aws_access_key_id=aws['aws_access_key_id'], aws_secret_access_key=aws['aws_secret_access_key'], region_name='us-east-2', mixpeek_api_key=mixpeek_api_key ) Upload one or more existing S3 files: # upload all S3 files in bucket "demo" s3.upload_all(bucket_name="demo") # upload one single file called "prescription.pdf" in bucket "demo" s3.upload_one(s3_file_name="prescription.pdf", bucket_name="demo") Now simply search using the Mixpeek module: # mixpeek api direct mix = Mixpeek( api_key=mixpeek_api_key ) # search result = mix.search(query="Heartgard") print(result) Where result can be: [ { "_id": "REDACTED", "api_key": "REDACTED", "highlights": [ { "path": "document_str", "score": 0.8759502172470093, "texts": [ { "type": "text", "value": "Vetco Prescription\nVetcoClinics.com\n\nCustomer:\n\nAddress: Canine\n\nPhone: Australian Shepherd\n\nDate of Service: 2 Years 8 Months\n\nPrescription\nExpiration Date:\n\nWeight: 41.75\n\nSex: Female\n\n℞ " }, { "type": "hit", "value": "Heartgard" }, { "type": "text", "value": " Plus Green 26-50 lbs (Ivermectin 135 mcg/Pyrantel 114 mg)\n\nInstructions: Give one chewable tablet by mouth once monthly for protection against heartworms, and the treatment and\ncontrol of roundworms, and hookworms. " } ] } ], "metadata": { "date_inserted": "2021-10-07 03:19:23.632000", "filename": "prescription.pdf" }, "score": 0.13313256204128265 } ]

然后解析结果

如果你在Windows上,没有时间找到一个好的grep替代品,一个快速而肮脏的方法是:

Aws s3 ls s3://your-bucket/folder/——recursive > myfile.txt

然后在myfile.txt中快速搜索

“文件夹”位是可选的。

附注:如果你没有安装AWS CLI -这里有一个使用Chocolatey包管理器的一行程序

Choco安装awscli

P.P.S.如果你没有巧克力包装管理器-得到它!你在Windows上的生活将变得更好10倍。(我和Chocolatey没有任何关系,但是嘿,这是一个必须要有的,真的)。

我是这样做的: 我在s3中有数千个文件。 我在列表中看到一个文件的属性面板。你可以看到该文件的URI,我复制粘贴到浏览器-这是一个文本文件,它呈现得很好。我用手边的uuid替换了url中的uuid文件就出来了。

我希望AWS有更好的方法来搜索文件,但这对我来说很管用。