GithubHelp home page GithubHelp logo

easy-es's Introduction

East-Es-Logo

Born To Simplify Development

maven code style

What is Easy-Es?

Easy-Es is a powerfully enhanced toolkit of RestHighLevelClient for simplify development. This toolkit provides some efficient, useful, out-of-the-box features for ElasticSearch. By using Easy-Es, you can use MySQL syntax to complete Es queries. Use it can effectively save your development time.

Links

Features

  • Auto configuration on startup
  • Out-of-the-box interfaces for operate es
  • Powerful and flexible where condition wrapper
  • Lambda-style API
  • Automatic paging operation
  • Support high-level syntax such as highlighting and weighting
  • ...

Compare

Demand: Query all documents with title equals "Hi" and author equals "Guy"

// Use Easy-Es to complete the query with only 3 lines of code
LambdaEsQueryWrapper<Document> wrapper = new LambdaEsQueryWrapper<>();
wrapper.eq(Document::getTitle, "Hi").eq(Document::getCreator, "Guy");
List<Document> documents = documentMapper.selectList(wrapper);
// Query with RestHighLevelClient requires 11 lines of code, not including parsing JSON code
String indexName = "document";
SearchRequest searchRequest = new SearchRequest(indexName);
BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
TermQueryBuilder titleTerm = QueryBuilders.termQuery("title", "Hi");
TermsQueryBuilder creatorTerm = QueryBuilders.termsQuery("creator", "Guy");
boolQueryBuilder.must(titleTerm);
boolQueryBuilder.must(creatorTerm);
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
searchSourceBuilder.query(boolQueryBuilder);
searchRequest.source(searchSourceBuilder);
try {
    SearchResponse searchResponse = restHighLevelClient.search(searchRequest, RequestOptions.DEFAULT);
    // Then parse the DocumentList from searchResponse in various ways, omitting these codes...
    } catch (IOException e) {
            e.printStackTrace();
    }

The above is just a simple query demonstration. The more complex the actual query scene, the better the effect, which can save 3-5 times the amount of code on average.

Getting started

  • Add Easy-Es dependency

    • Latest Version: Maven Central
    • Maven:
      <dependency>
        <groupId>com.github.xpc1024</groupId>
        <artifactId>easy-es-boot-starter</artifactId>
        <version>Latest Version</version>
      </dependency>
    • Gradle
      compile group: 'com.github.xpc1024', name: 'easy-es-boot-starter', version: 'Latest Version'
  • Add mapper file extends BaseEsMapper interface

    public interface DocumentMapper extends BaseMapper<User> {
    }
  • Use it

    LambdaEsQueryWrapper<Document> wrapper = new LambdaEsQueryWrapper<>();
    wrapper.eq(Document::getTitle,"Hello World")
           .eq(Document::getCreator,"Guy");
    List<Document> documentList = documentMapper.selectList();

    Easy-Es will execute the following Query:

    {"query":{"bool":{"must":[{"term":{"title":{"value":"Hello World","boost":1.0}}},{"term":{"creator":{"value":"Guy","boost":1.0}}}],"adjust_pure_negative":true,"boost":1.0}}}

    The syntax of this query in MySQL is:

     SELECT * FROM document WHERE title = 'Hello World' AND creator = 'Guy'

This showcase is just a small part of Easy-Es features. If you want to learn more, please refer to the documentation.

Syntax comparison with MySQL

MySQL Easy-Es
and and
or or
= eq
!= ne
> gt
>= ge
< lt
<= le
like '%field%' like
not like '%field%' notLike
like '%field' likeLeft
like 'field%' likeRight
between between
notBetween notBetween
is null isNull
is notNull isNotNull
in in
not in notIn
group by groupBy
order by orderBy
min min
max max
avg avg
sum sum
sum sum
- orderByAsc
- orderByDesc
- match
- highLight
... ...

Donate

Donate Easy-Es

License

Easy-Es is under the Apache 2.0 license. See the Apache License 2.0 file for details.

easy-es's People

Contributors

xpc1024 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.