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


当前回答

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

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

其他回答

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

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

虽然不是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 } ]

然后解析结果

我做了如下的事情来在我的桶中寻找模式

def getListOfPrefixesFromS3(dataPath: String, prefix: String, delimiter: String, batchSize: Integer): List[String] = {
    var s3Client = new AmazonS3Client()
    var listObjectsRequest = new ListObjectsRequest().withBucketName(dataPath).withMaxKeys(batchSize).withPrefix(prefix).withDelimiter(delimiter)
    var objectListing: ObjectListing = null
    var res: List[String] = List()

    do {
      objectListing = s3Client.listObjects(listObjectsRequest)
      res = res ++ objectListing.getCommonPrefixes
      listObjectsRequest.setMarker(objectListing.getNextMarker)
    } while (objectListing.isTruncated)
    res
  }

对于较大的存储桶,这会消耗太多时间,因为所有对象摘要都由Aws返回,而不仅仅是匹配前缀和分隔符的对象。我正在寻找提高性能的方法,到目前为止,我只发现我应该命名键,并将它们正确地组织在桶中。

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

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

这里要补充一点:现在已经3年了,但当你输入“如何搜索S3 Bucket”时,这篇文章是谷歌的顶部。

也许你正在寻找一些更复杂的东西,但如果你在这里试图弄清楚如何简单地通过标题找到一个对象(文件),这是疯狂的简单:

打开桶,选择右边的“none”,并开始输入文件名。

http://docs.aws.amazon.com/AmazonS3/latest/UG/ListingObjectsinaBucket.html