WYSIWYG

http://kufli.blogspot.com
http://github.com/karthik20522

Tuesday, April 14, 2015

ReIndexing Elasticsearch in Scala

The following scala script reads from one index and writes to another script using Scan and scroll method. The script also takes in a partial function where the values from one index can be manipulated before saving into another index. This script assumes you have a field called "id" and an field called "submitDate" so it can continually perform scan and scroll once the preliminary index copy is done, so keep the index's in sync. Notes:
  • The ESClient is an extension of on wabisabi Library for elasticsearch
  • The Actor initially performs a scan-scroll with submit date gte 1900
  • Once the initial scan-scroll is done, it pauses for a minute and performs a scan-scroll again with the submitDate of previous endTime (dateTime.now minus 1 minute)
  • This way every minute after the previous run it will continually keep the index in sync
  • The partial function "processData" provides a way to manipulate the original data, manipulate it and save it to the new index
  • Bulk-indexing is used for saving to the new index, hence a the "id" field is required to determine the "id" of the new document
Usage:

Labels: , ,

Saturday, August 9, 2014

AKKA.NET Actor Creation - Typed, Untyped, Receive Actor

There are three potential ways of creating Actors using Akka.net (v0.6.2).

1. Using Receive Actor: In order to use the Receive() method inside an actor the actor must inherit from ReceiveActor. All message handling must be part of the constructor. Please note that handler matches, the one that appears first is used. More info Akka.net documentation.

2. Using Typed Actor: In typed actor, you explicitly provide the message types that the actor would receive. This is very helpful in code readability as you are ware if type of message that the actor receives. For receive message, you need to define a overloaded "Handle" function with message types.

3. Using Untyped Actor: Untyped Actor, similar to Receive actor requires to pattern match the message type. For using Untyped actor, the OnReceive function needs to be overridden.
Handling unknown messages can be done 2 ways:

Labels: , ,