1

I'm having some trouble getting elastic search integrated with an existing application, but it should be a fairly straightforward issue. I'm able to create and destroy indices but for some reason I'm having trouble getting data into elastic search and querying for it.

I'm using the pyes library and honestly finding the documentation to be less than helpful on this front. This is my current code:

def initialize_transcripts(database, mapping):
    database.indices.create_index("transcript-index")


def index_course(database, sjson_directory, course_name, mapping):
    database.put_mapping(course_name, {'properties': mapping}, "transcript-index")
    all_transcripts = grab_transcripts(sjson_directory)
    video_counter = 0
    for transcript_tuple in all_transcripts:
        data_map = {"searchable_text": transcript_tuple[0], "uuid": transcript_tuple[1]}
        database.index(data_map, "transcript-index", course_name, video_counter)
        video_counter += 1
    database.indices.refresh("transcript-index")


def search_course(database, query, course_name):
    search_query = TermQuery("searchable_text", query)
    return database.search(query=search_query) 

I'm first creating the database, and initializing the index, then trying to add data in and search it with the second two methods. I'm currently getting the following error:

raise ElasticSearchException(response.body, response.status, response.body)
pyes.exceptions.ElasticSearchException: No handler found for uri [/transcript-index/test-course] and method [PUT]

I'm not quite sure how to approach it, and the only reference I could find to this error suggested creating your index beforehand which I believe I am already doing. Has anyone run into this error before? Alternatively do you know of any good places to look that I might not be aware of?

Any help is appreciated.

Slater Victoroff
  • 21,376
  • 21
  • 85
  • 144
  • not an answer but I've looked at a few libraries for elasticsearch and none of them were a big improvement over interacting with it using the requests module. With Elastic Search's complex DSL there's so much for a library to do. How have you found pyes in general? – Transact Charlie Jun 04 '13 at 20:54
  • To be honest, not fantastic. It makes simple things trivial, but the documentation is generally lacking and it seems to obfuscate a lot of useful functionality extended by ES. Do you have any resources for interacting solely through the requests module? I think I might want to switch over to that. – Slater Victoroff Jun 04 '13 at 21:00
  • in python it's really easy. Don't have any favourite links but google is probably your friend. Requests make it easy to post to ES with a json payload (the query). When you start dealing with tons of filters and facets then (IMO only) it's quite nice to have your request logic as a json document and then pass it to ES -- kinda like a stored proc in a relational DB. Also love python json library for deserialising the result into a dict!!! – Transact Charlie Jun 04 '13 at 21:07
  • liked the "makes simple things trivial" comment -- just had to write a board presentation about why we should use Elastic Seach rather than Solr -- I think that Solr also makes easy things easy but complex things difficult -- ElasticSearch has a much more flat difficulty -- nothing is truly easy, but the DSL makes complicated things much more straightforward in the end. – Transact Charlie Jun 04 '13 at 21:11
  • Wanna thank you for the suggestion to directly use requests. I switched to using that instead of pyes and I've never been happier. Their REST api is also fantastically documented. – Slater Victoroff Jun 06 '13 at 22:20

1 Answers1

3

For some reason, adding the ID to the index, despite the fact that it is shown in the starting documentation: (http://pyes.readthedocs.org/en/latest/manual/usage.html) doesn't work, and in fact causes this error.

Once I removed the video_counter argument to index, this worked perfectly.

Slater Victoroff
  • 21,376
  • 21
  • 85
  • 144
  • Weird, check what you're using now as id for your documents, maybe it gets auto-generated, which might not be what you want. – javanna Jun 04 '13 at 20:10
  • It seems to be auto-generated, I've moved on from pyes though, simply too much of a headache to deal with. – Slater Victoroff Jun 06 '13 at 22:19