简体   繁体   中英

How to upload JSON to AWS CloudSearch

Seems like I missing some pretty simple things, but can't figureout what's a problem here. I want to upload JSON file which is next:

[{
    "name": "Mark"
}]

After create an Index field name : 在此处输入图片说明

Then I pick Upload Documents on a Dashboard page: 在此处输入图片说明

And then I have an error:

Your upload includes 1 document containing the following fields: content content_encoding content_type resourcename

在此处输入图片说明

What am I do wrong ?

I am currently trying to use it and I have the same problem.

Try this :

1/ Create a JSON batch to add your data to your search domain

For example :

[
  {
    "type": "add",
    "id": "uniqueid:1",
    "fields": {
        "name": "jack",
    }
  },
  {
    "type": "add",
    "id": "uniqueid:2",
    "fields": {
        "name": "pierre",
    }
  },
  {
    "type": "add",
    "id": "uniqueid:3",
    "fields": {
        "name": "bob",
    }
  }
]

2/ Now go to your domains dashboard and click "upload document" : upload this JSON batch

3/ Go to "run a test search" and try to find "bob" for example : you should have your bob data !

The documentation about the batch : https://docs.aws.amazon.com/cloudsearch/latest/developerguide/preparing-data.html

To upload data to your search domain you need to respect this batch format, look the documentation and the guidelines :)

You can do it too using a bucket that will be use to trigger a lambda function, the idea is : when you will upload a file in the bucket, launch your lambda function to read this file and create a batch file that will add the new data to your index. And when you remove a file : you delete the data to your index !

Look this tutorial if you need some help with the lambda function : https://medium.com/devopslinks/build-your-own-document-search-engine-using-amazon-web-services-82d5b165d96c

Hope it helps !

[
  {
    'type': 'add',
    'id': 'item1',
    'fields': {
        'name': 'salt',
    }
  },
  {
    'type': 'add',
    'id': 'item2',
    'fields': {
        'name': 'sugar',
    }
  },
  {
    'type': 'add',
    'id': 'item3',
    'fields': {
        'name': 'rice',
    }
  }
]

I tried to upload the above data, but I was getting error. So, I modified single quote ' to double quote ", and it worked out. I was able to upload to aws cloudsearch.

[
  {
    "type": "add",
    "id": "item1",
    "fields": {
        "name": "salt",
    }
  },
  {
    "type": "add",
    "id": "item2",
    "fields": {
        "name": "sugar",
    }
  },
  {
    "type": "add",
    "id": "item3",
    "fields": {
        "name": "rice",
    }
  }
]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM