Websockets with Elasticsearch ScrollPublisher - Requesting more elements

147 views
Skip to first unread message

Muki

unread,
Oct 2, 2015, 11:29:09 AM10/2/15
to Akka User List
Hi,

I'm playing around with akka-http and elasti4s reactive extension. My goal is rather simple: I want to stream the elasticsearch results via websocket on request

  1. Open a websocket ( wscat -c ws://localhost:9000/es/scroll )
  2. Place a query ( >search:my search term )
  3. Get always a bunch (e.g. 5) results and get the next results with >next
 val commandTriggeredFlow = Flow() { implicit b =>
     import FlowGraph.Implicits._
     // broadcast the command to the elasticsearch source and the tick system
     val bcast = b.add(Broadcast[Command](2))
     val zip = b.add(Zip[Command, Seq[Question]]())

          // forward the ticks

    bcast.out(0) ~> zip.in0
        
    // filter out the Next commands
    bcast.out(1)
       .filter(_.isInstanceOf[Search])
       .map {
         case Search(term) => query(term)
       }
       .flatten(FlattenStrategy.concat)
       // group results to get a "per next result batch"
       .grouped(2) ~> zip.in1

   (bcast.in, zip.out)
}

I had the idea to parse the commands from the websocket and only create a new search on a search command and otherwise trigger the elasticsearch ScrollPublisher source.
Well. That doesn't work :D

> search:first

< (Search(first),Vector(Question(1,First Question ever asked!,This is my first question!), Question(1,First Question ever asked!,This is my first question!)))
> next



I'm getting the results in a batch for my first search. But when I hit next the stream seems not be triggered.
I couldn't find any examples for this :(

cheers,
Muki

Muki

unread,
Oct 11, 2015, 11:14:23 AM10/11/15
to Akka User List
Hi,

I implemented a working solution and will soon provide it as an activator template. 


cheers,
Muki

Patrik Nordwall

unread,
Oct 19, 2015, 5:53:09 AM10/19/15
to akka...@googlegroups.com
Cool, thanks for sharing!
/Patrik

--
>>>>>>>>>> Read the docs: http://akka.io/docs/
>>>>>>>>>> Check the FAQ: http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user
---
You received this message because you are subscribed to the Google Groups "Akka User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to akka-user+...@googlegroups.com.
To post to this group, send email to akka...@googlegroups.com.
Visit this group at http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.



--

Patrik Nordwall
Typesafe Reactive apps on the JVM
Twitter: @patriknw

Reply all
Reply to author
Forward
0 new messages