<div dir="ltr">Yeap, it was elasticsearch.<div><br></div><div>Had to call <a href="http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/indices-refresh.html">http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/indices-refresh.html</a> to force update on indexing of documents.</div>
<div><br></div><div>Sorry to bother everybody ;_;</div><div><br></div><div>Thank you so much for your help.</div><div><br></div><div>Have a great day :)</div><div><br></div><div>--- Chris</div><div><br></div></div><div class="gmail_extra">
<br><br><div class="gmail_quote">On Thu, Apr 10, 2014 at 1:28 AM, Michael Snoyman <span dir="ltr"><<a href="mailto:michael@snoyman.com" target="_blank">michael@snoyman.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr">http-conduit does not perform any kind of automatic concurrency. httpLbs will only return after it has fully read the response body from the server. So unless there's a bug somewhere in http-conduit, it seems that the server has not fully updated its index by the time it gives back a response.</div>
<div class="HOEnZb"><div class="h5">

<div class="gmail_extra"><br><br><div class="gmail_quote">On Thu, Apr 10, 2014 at 9:25 AM, Christopher Allen <span dir="ltr"><<a href="mailto:cma@bitemyapp.com" target="_blank">cma@bitemyapp.com</a>></span> wrote:<br>


<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">the function actually running the requests is:<div><br></div><div><div>dispatch :: String -> Method -> Maybe L.ByteString</div>


<div>            -> IO Reply</div><div>dispatch url method body = do</div>
<div>  initReq <- parseUrl url</div><div>  let reqBody = RequestBodyLBS $ fromMaybe emptyBody body</div><div>  let req = initReq { method = method</div><div>                    , requestBody = reqBody</div><div>                    , checkStatus = \_ _ _ -> Nothing}</div>



<div>  withManager $ httpLbs req</div></div><div><br></div><div>rest of the code is here: <a href="https://github.com/bitemyapp/bloodhound/" target="_blank">https://github.com/bitemyapp/bloodhound/</a></div></div><div>

<div><div class="gmail_extra">
<br><br><div class="gmail_quote">On Thu, Apr 10, 2014 at 1:25 AM, Christopher Allen <span dir="ltr"><<a href="mailto:cma@bitemyapp.com" target="_blank">cma@bitemyapp.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">



<div dir="ltr">It's a step removed from that, and `seq`'ing insertData isn't fixing it, only a threadDelay is.<div><br></div><div>The operations insertData is performing are:</div><div>delete index, create index, add document to index</div>




<div><br></div><div>the operation queryTweet is performing is:</div><div>search index</div><div><br></div><div>The behavior seems to indicate "search index" is happening before "add document to index" and after "delete index", as the document will not exist when the query is performed.</div>




<div><br></div><div>Only adding a threadDelay as reliably worked. Even `seq`'ing insertData doesn't work.</div><div><br></div><div>Are the requests somehow being performed concurrently?</div><div><br></div></div>



<div><div><div class="gmail_extra">
<br><br><div class="gmail_quote">On Thu, Apr 10, 2014 at 1:15 AM, Michael Snoyman <span dir="ltr"><<a href="mailto:michael@snoyman.com" target="_blank">michael@snoyman.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">




<div dir="ltr">I can't say I fully understand your code, but it seems like it's doing the following:<div><br></div><div>1. Send request to server to delete data.</div><div>2. Send request to server to add data.</div>






<div>3. Request data from server.</div><div><br></div><div>You're saying that with a long enough delay between steps 2 and 3, then (3) works, otherwise it fails. It sounds to me like there's some kind of a race condition. I don't know anything about createExampleIndex, but are you certain that it only returns after the data is completely ready for querying?</div>






</div><div class="gmail_extra"><br><br><div class="gmail_quote"><div><div>On Thu, Apr 10, 2014 at 8:43 AM, Christopher Allen <span dir="ltr"><<a href="mailto:cma@bitemyapp.com" target="_blank">cma@bitemyapp.com</a>></span> wrote:<br>






</div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div><div dir="ltr">to add to my question adding a delay made it work:<div><br></div><div>
<div><div>main :: IO ()</div>

<div>main = do</div><div>  _ <- insertData</div></div><div>  threadDelay 1000000</div><div><div>  myTweet <- queryTweet</div>
<div>  print myTweet</div></div></div><div><br></div></div><div><div><div class="gmail_extra"><br><br><div class="gmail_quote">On Thu, Apr 10, 2014 at 12:41 AM, Christopher Allen <span dir="ltr"><<a href="mailto:cma@bitemyapp.com" target="_blank">cma@bitemyapp.com</a>></span> wrote:<br>







<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>Repro'd on GHC 7.8.1 and 7.6.3</div><div><br></div>Original code is: <a href="https://github.com/bitemyapp/bloodhound/" target="_blank">https://github.com/bitemyapp/bloodhound/</a><br>







<br>The code only works if I manually (out of band) run insertData (in a REPL) and then run main with the insertData invocation stripped out. If I run main with the insertData invocation included, it throws an exception (head) because the search results are empty.<div>








<br>The behavior is as if queryTweet was executing after insertData deleted the index, but before it inserted the new data.<br><br>The following is a stripped down example:<br><br>insertData :: IO ()<br>insertData = do<br>








  let encoded = encode exampleTweet<br>  _ <- deleteExampleIndex<br>  created <- createExampleIndex<br>  docCreated <- indexDocument (Server "<a href="http://localhost:9200" target="_blank">http://localhost:9200</a>") "twitter" "tweet" exampleTweet "1"<br>








  print "test"<br>  return ()<br>el<br>queryTweet :: IO (Either String Tweet)<br>queryTweet = do<br>  let queryFilter = BoolFilter (MustMatch (Term "user" "bitemyapp") False)<br>                    <||> IdentityFilter<br>








  let search = Search Nothing (Just queryFilter)<br>  reply <- searchByIndex testServer "twitter" search<br>  let result = eitherDecode (responseBody reply) :: Either String (SearchResult Tweet)<br>  let myTweet = fmap (hitSource . head . hits . searchHits) result<br>








  return myTweet<br><br>main :: IO ()<br>main = do<br>  _ <- insertData<br>  myTweet <- queryTweet<br>  print myTweet</div><div><br></div><div>further up the call chain, the http call is getting dispatched with http-conduit's gear, the result returned with the expression:</div>








<div><br></div><div>withManager $ httpLbs req<br></div><div><br></div><div>Included this in case it affects the semantics.</div><div><br></div><div>Can anybody help? This has stumped me for a couple hours and I couldn't get anything clueful on IRC.<br>








</div><div><br></div><div>Thanks to any that help.</div><div><br></div><div>--- Chris</div><div><br></div></div>
</blockquote></div><br></div>
</div></div><br></div></div>_______________________________________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org" target="_blank">Beginners@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/beginners" target="_blank">http://www.haskell.org/mailman/listinfo/beginners</a><br>
<br></blockquote></div><br></div>
<br>_______________________________________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org" target="_blank">Beginners@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/beginners" target="_blank">http://www.haskell.org/mailman/listinfo/beginners</a><br>
<br></blockquote></div><br></div>
</div></div></blockquote></div><br></div>
</div></div><br>_______________________________________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org" target="_blank">Beginners@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/beginners" target="_blank">http://www.haskell.org/mailman/listinfo/beginners</a><br>
<br></blockquote></div><br></div>
</div></div><br>_______________________________________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org">Beginners@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/beginners" target="_blank">http://www.haskell.org/mailman/listinfo/beginners</a><br>
<br></blockquote></div><br></div>