bitemyapp / bloodhound

Haskell Elasticsearch client and query DSL
bitemyapp.com
BSD 3-Clause "New" or "Revised" License
424 stars 118 forks source link

Fix improve example #198

Closed yannick-cw closed 7 years ago

yannick-cw commented 7 years ago

Hi, I had a hard time figuring out how to parse the responses for searches. When trying to run the example I also found out some stuff was not working :)

I'd like to add an example here for parsing and I fixed the geo object datatype, as it only accepts lat, lon now as field names.

I am just starting to learn haskell, so please forgive me if something is bad style.

bitemyapp commented 7 years ago

Thank you for putting this up! I apologize for not getting to it sooner :cry:

I merged the other PR which fixed this, so hopefully nobody else trips over this.

yannick-cw commented 7 years ago

@bitemyapp perfect :) What do you think of extending the example file with the reply parsing?

 reply <- searchByType testIndex testMapping search
 Right searchResult <- parseEsResponse reply :: BH IO (Either EsError (SearchResult Tweet))
 let tweets = fmap hitSource (hits $ searchHits searchResult) >>= maybeToList
 liftIO (print tweets)
bitemyapp commented 7 years ago

@yannick-cw I think it'd be a good idea for it to do that and to detect errors, throwing an exception if one occurs.