1

Hi I am trying to add documents to a cloudsearch domain as per

http://docs.pythonboto.org/en/latest/cloudsearch_tut.html#adding-documents-to-the-index

my code snppet is:

import boto
conn = boto.connect_cloudsearch(aws_access_key_id='<>',aws_secret_access_key='<>')
domain = conn.lookup('testfoo')
doc_service = domain.get_document_service()
doc_service.add(doc_id, version, data)

First I got the same requests issues Boto CloudSearch on GAE: TypeError: request() got an unexpected keyword argument 'config'

and so I removed the config kwarg (also not sure of the consequences) and then I get

boto.cloudsearch.document.CommitMismatchError: Incorrect number of adds returned. Commit: 1 Response: 0

My data is like this

[
{
        "raw" : "whole bunch of raw text",
        "title" : "My new title",
        "blurb" : "A really exciting article",
        "document_type" : "Tech Guide",
        "url" : "http://www.foobar/7199/tech-advice"
}
]

Any help greatly appreciated

Community
  • 1
  • 1

2 Answers2

1

It turns out the problem is when I built up the json in data it is not json but a string. So when this produces the json being sent to the cloudsearch domain and it combines the id and "Add" operation it includes "fields": "[ { "raw" : "whole bunch of raw text", "title" : "My new title", "blurb" : "A really exciting article", "document_type" : "Tech Guide", "url" : "http://www.foobar/7199/tech-advice" } ]" as a string

The solution is simply data needs json encoding

doc_service.add(doc_id, version, json.loads(data))

0

Here just remove [] from data. Because if you have single object then you must pass it with dictionay. {}

[ { "raw" : "whole bunch of raw text", "title" : "My new title", "blurb" : "A really exciting article", "document_type" : "Tech Guide", "url" : "http://www.foobar/7199/tech-advice" } ]

jatinkumar patel
  • 2,920
  • 21
  • 28