Elasticsearch's Javaapi query dsl-filters

Source: Internet
Author: User

Elasticsearch's Javaapi query dsl-filters

and theLike the REST query DSL, Elasticsearch provides a complete Java query DSL. The Factory filter Builder is FilterBuildersOnce you have your query ready, you can use the query API.

How do I build a query? Use FilterBuilders,import them in your class:

Import org.elasticsearch.index.query.filterbuilders.*;


Please note that the FilterBuilderObject can easily print (aka Debug) The JSON generated by the query, using the toString()Method.





Here are a few commonFiler

Andfilter

Filterbuilders.andfilter (


filterbuilders.rangefilter ("Postdate"). From ("2010-03-01"). to ("2010-04-01"),


filterbuilders.prefixfilter ("Name.second", "BA")


    );


Note, you can cache the results, using the AndFilterBuilder#cache(boolean)Method.



BOOL Filter

Filterbuilders.boolfilter ()


. Must (Filterbuilders.termfilter ("tag", "Wow"))


. Mustnot ("Filterbuilders.rangefilter"). From ("Ten") . to (" a"))


. Should (Filterbuilders.termfilter ("tag", "Sometag"))


. Should (Filterbuilders.termfilter ("tag", "Sometagtag"));


Use BoolFilterBuilder#cache(boolean)Method Cache Results



EXISTS filter

filterbuilders.existsfilter ("user");




Matchall Filter

Filterbuilders.matchallfilter ();




Notfilter

Filterbuilders.notfilter (


filterbuilders.rangefilter ("Price"). From ("1"). to ("2"));




or filter

Filterbuilders.orfilter (


filterbuilders.termfilter ("Name.second", "Banon"),


filterbuilders.termfilter ("Name.nick", "Kimchy")


    );


OrFilterBuilder#cache(boolean)Method Cache Results



Query filter

Filterbuilders.queryfilter (


querybuilders.querystring ("This and that OR thus")


    );


QueryFilterBuilder#cache(boolean)Method Cache Results



Range Filter

filterbuilders.rangefilter ("Age")


. From ("Ten")


. to (" a")


. Includelower (True)


. Includeupper (false);




//A simplified form using GTE, GT, LT or LTE


filterbuilders.rangefilter ("Age")


. GTE ("ten")


. LT ("a");


RangeFilterBuilder#cache(boolean)Method Cache Results

T

Term filter

Filterbuilders.termfilter ("User", "Kimchy");

你可以使用 TermFilterBuilder#cache(boolean)method does not apply to caching.

T

Terms Filter

filterbuilders.termsfilter ("User", "Kimchy", "Elasticsearch")


. Execution ("plain"); Optional, can be also "bool", "and" or "or"


//or "Bool_nocache", "And_nocache" or "Or_nocache"


你可以不使用缓存,用 TermsFilterBuilder#cache(boolean)Method



Cache

By default, some filters are cached, some do not cache. You can have a good control of usingCache (Boolean) method is present. For example:

FilterbuilderFilter=filterbuilders.Andfilter(


        filterbuilders.rangefilter ("Postdate"). From ("2010-03-01"). to ("2010-04-01"),


filterbuilders.prefixfilter ("Name.second", "BA")


        )


. Cache (TRUE);



Elasticsearch's Javaapi query dsl-filters

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.