GithubHelp home page GithubHelp logo

wl21st / storm-trident-elasticsearch Goto Github PK

View Code? Open in Web Editor NEW

This project forked from fhussonnois/storm-trident-elasticsearch

0.0 1.0 0.0 279 KB

Trident State implementation on top of Elasticsearch

License: Apache License 2.0

Java 100.00%

storm-trident-elasticsearch's Introduction

Apache Storm - Elasticsearch

Apache Storm is a free and open source distributed realtime computation system.

Bolt/Trident API implementation for Elasticsearch

This library provides core storm bolt and implements a Trident state on top of Elasticsearch. It supports non-transactional, transactional, and opaque state types.

Maven dependency

    <dependency>
      <groupId>com.github.fhuss</groupId>
      <artifactId>storm-elasticsearch</artifactId>
      <version>0.3.0</version>
    </dependency>

TupleMapper / TridentTupleMapper

To index documents into elasticsearch you need to provide an implementation of following interfaces according to you use bolt or trident state.

These two interfaces have only one method defined used to map tuple fields to a Document.

    public interface TupleMapper<T> extends Serializable {
       T map(Tuple input);
    }
    public interface TridentTupleMapper<T> extends Serializable {
       T map(TridentTuple input);
    }

To be indexed, a document requires at least following attributes:

  • The name of the index
  • The type of document
  • The source document

For general use cases, a default implementation is provided DefaultTupleMapper.

Core Bolt / IndexBatchBolt

The IndexBatchBolt implementation relies on storm tick tuple feature and Elasticsearch Bulk API to index many tuples.

Trident State examples

Persistent Aggregate

    FixedBatchSpout spout = new FixedBatchSpout(new Fields("sentence"), 3,
                new Values("the cow jumped over the moon"),
                new Values("the man went to the store and bought some candy"),
                new Values("four score and seven years ago"),
                new Values("how many apples can you eat"),
                new Values("to be or not to be the person"));
    spout.setCycle(true);

    TridentTopology topology = new TridentTopology();

    Settings settings = ImmutableSettings.settingsBuilder().loadFromClasspath("elasticsearch.yml").build();
    StateFactory stateFactory = ESIndexMapState.nonTransactional(new ClientFactory.LocalTransport(settings.getAsMap()), Tweet.class);
        
    topology.newStream("tweets", spout)
            .each(new Fields("sentence"), new DocumentBuilder(), new Fields("document"))
            .each(new Fields("document"), new ExtractDocumentInfo(), new Fields("id", "index", "type"))
            .groupBy(new Fields("index", "type", "id"))
            .persistentAggregate(stateFactory, new Fields("document"), new TweetBuilder(), new Fields("tweet"))
            .parallelismHint(1);

Search query using DRPC

    TridentTopology topology = new TridentTopology();

    Settings settings = ImmutableSettings.settingsBuilder().loadFromClasspath("elasticsearch.yml").build();
    TridentState staticState = topology.newStaticState(new ESIndexState.Factory<>(new LocalTransport(settings.getAsMap()), Tweet.class));
    topology.newDRPCStream("search", drpc)
            .each(new Fields("args"), new ExtractSearchArgs(), new Fields("query", "indices", "types"))
            .groupBy(new Fields("query", "indices", "types"))
            .stateQuery(staticState, new Fields("query", "indices", "types"), new QuerySearchIndexQuery(), new Fields("tweet"))
            .each(new Fields("tweet"), new FilterNull())
            .each(new Fields("tweet"), new CreateJson(), new Fields("json"))
            .project(new Fields("json"));

License

Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

storm-trident-elasticsearch's People

Contributors

fhussonnois avatar obourgain avatar jeromebrionne avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.