Giter Site home page Giter Site logo

esmapper's Introduction

esmapper

CircleCI

SYNOPSIS

Stream<EntryBean> beanStream = elasticsearchMapper.findAll(
    client.prepareSearch("blog")
        .setTypes("entry")
        .addSort("title", SortOrder.ASC),
    3,
    EntryBean.class
);
beanStream.map(EntryBean::getTitle).forEach(System.out::println);

DESCRIPTION

Tiny elasticsearch mapper for Java. Mapping search results to Java objects.

INSTALL

You can install this library from maven central.

See http://search.maven.org/#search%7Cga%7C1%7Cg%3A%22me.geso.esmapper%22

METHODS

Future<Long> count(SearchRequestBuilder searchRequestBuilder)

    Future<Long> countFuture = elasticsearchMapper.count(
            client.prepareSearch("blog")
                    .setTypes("entry")
    );

Count search results.

This method automatically adds searchRequestBuilder.setSize(0).

Returns the number of total hit rows.

public <T> Stream<T> findAll(SearchRequestBuilder searchRequestBuilder, int scrollSize, Class<T> klass) throws JsonParseException, JsonMappingException

    Stream<EntryBean> beanStream = elasticsearchMapper.findAll(
            client.prepareSearch("blog")
                    .setTypes("entry")
                    .addSort("title", SortOrder.ASC),
            3,
            EntryBean.class
    );
  • searchRequestBuilder is search query.
  • scrollSize is scroll window size for each request.
  • klass is a mapping class type.

Get all results from search query using scrolling.

Throws JsonParseException and JsonMappingException if there's JSON mapping exception.

Returns search result stream.

This method throws RuntimeException if TODO: We shouldn't throw it.

public <T> Future<Page<T>> findPagination(int page, int entriesPerPage, SearchRequestBuilder searchRequestBuilder, Class<T> klass)

Page<EntryBean> page = elasticsearchMapper.findPagination(
    1,
    3,
    client.prepareSearch("blog")
          .setTypes("entry")
          .addSort("title", SortOrder.ASC),
    EntryBean.class
).get();

Find results with pagination.

  • page is current page number.
  • entriesPerPage is the number of entries per page.
  • searchRequestBuilder is a search request.
  • klass is a mapping class type.

Returns search results. Page<T> object contains total number of hits and rows information.

public <T> Future<LoadMore<T>> findLoadMore(int entriesPerPage, SearchRequestBuilder searchRequestBuilder, Class<T> klass)

LoadMore<EntryBean> page = elasticsearchMapper.findLoadMore(
    3,
    client.prepareSearch("blog")
        .setTypes("entry")
        .addSort("title", SortOrder.ASC)
        .setQuery(QueryBuilders.rangeQuery("i").gt(2)),
    EntryBean.class
).get();

Find rows for "Load more" style navigation.

  • entriesPerPage is the number of rows in per page.
  • searchRequestBuilder is query object.
  • klass is mapping type.

Returns search results. You can call hasNext() and getRows() method via page object.

public <T> Future<Optional<T>> findFirst(SearchRequestBuilder searchRequestBuilder, Class<T> klass)

Future<Optional<EntryBean>> optionalFuture = elasticsearchMapper.findFirst(
    client.prepareSearch("blog")
        .setTypes("entry")
        .setQuery(QueryBuilders.termQuery("_id", indexResponses.get(4).getId())),
    EntryBean.class
);

Find first element and map to Optional.

  • searchRequestBuilder is query object.
  • klass is mapping type.

SEE ALSO

esmapper's People

Contributors

tokuhirom avatar

Watchers

 avatar James Cloos avatar  avatar

esmapper's Issues

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.