Select wrapper
# LambdaEsQueryWrapper
提示
This conditional constructor is mainly used for wrapping the query conditions required when querying data
# allEq
allEq(Map<R, V> params)
2
alleq
Individual parameter descriptions
params : key is the database field name, value is the field value
- Example: allEq({id:1,name: "Lao Wang",age:18})--->id = 1 and name = 'Lao Wang' and age = 18
allEq(BiPredicate<R, V> filter, Map<R, V> params)
2
Individual parameter descriptions
filter : filter function, whether to allow fields to be passed into the comparison condition params and null2IsNull : same as above
- Example: allEq((k,v) -> k.indexOf("a") >= 0, {id:1,name: "Lao Wang",age:18}) ---> name = 'Lao Wang' and age = 18
# eq
eq(R column, Object val)
eq(boolean condition, R column, Object val)
2
- is equivalent to =
- Example: eq("name", "Lao Wang") ---> name = 'Lao Wang'
# gt
gt(R column, Object val)
gt(boolean condition, R column, Object val)
2
- greater than >
- Example: gt("age", 18) ---> age > 18
# ge
ge(R column, Object val)
ge(boolean condition, R column, Object val)
2
- greater than or equal to >=
- Example: ge("age", 18) ---> age >= 18
# lt
lt(R column, Object val)
lt(boolean condition, R column, Object val)
2
- Less than <
- Example: lt("age", 18)--->age < 18
# le
le(R column, Object val)
le(boolean condition, R column, Object val)
2
- Less than or equal to <=
- Example: le("age", 18)--->age <= 18
# between
between(R column, Object val1, Object val2)
between(boolean condition, R column, Object val1, Object val2)
2
- BETWEEN value1 AND value2
- Example: between("age", 18, 30)--->age between 18 and 30
# like
like(R column, Object val)
like(boolean condition, R column, Object val)
2
- LIKE '%value%'
- Example: like("name", "Wang") ---> name like '%King%'
# likeLeft
likeLeft(R column, Object val)
likeLeft(boolean condition, R column, Object val)
2
- LIKE '% value'
- Example: likeLeft("name", "Wang") ---> name like '%Wang'
# likeRight
likeRight(R column, Object val)
likeRight(boolean condition, R column, Object val)
2
- LIKE 'value%'
- Example: likeRight("name", "Wang") ---> name like 'Wang%'
# isNotNull
isNotNull(R column)
isNotNull(boolean condition, R column)
2
- field IS NOT NULL
- Example: isNotNull(Document::getTitle)--->title is not null
# exists
exists(R column)
exists(boolean condition, R column)
2
The effect and function is equivalent to the above isNotNull, mainly to take care of es native syntax habit of the user
# in
in(R column, Collection<? > value)
in(boolean condition, R column, Collection<? > value)
2
- field in (value.get(0), value.get(1), ...)
- Example: in("age",{1,2,3})---> age in (1,2,3)
in(R column, Object... values)
in(boolean condition, R column, Object... values)
2
- field in (v0, v1, ...)
- Example: in("age", 1, 2, 3)---> age in (1,2,3)
# groupBy
groupBy(R... columns)
groupBy(boolean condition, R... columns)
2
- Grouping: GROUP BY fields, ...
- Example: groupBy(Document::getId,Document::getTitle)--->group by id,title
# orderByDesc
orderByDesc(R... columns)
orderByDesc(boolean condition, R... columns)
2
- Sort by: ORDER BY fields, ... DESC
- Example: orderByDesc(Document::getId,Document::getTitle)--->order by id DESC,title DESC
# limit
limit(Integer n);
limit(Integer m, Integer n);
2
3
- limit n returns the maximum number of data, equivalent to n in MySQL's limit n, the usage is the same.
- limit m,n skips m data and returns up to n data, which is equivalent to MySQL's limit m,n or offset m limit n.
- Example: limit(10)--->Returns up to 10 data items
- Example: limit(2,5)--->Skip the first 2 data, start from the 3rd one, and query 5 data in total
提示
If n parameter is not specified, the default value is 10000 If your single query more than 1W, it is recommended to use paging (refer to the section on paging later), if you have to specify more than 1w here, for example, specify 2w, you need to add the annotation @IndexName(maxResultWindow=20000) on the entity class of the query Specify its maxResultWindow, and rebuild the index, otherwise es will report an error, this is the rule of es, it should make this limit to protect your memory to prevent overflow. If you do not want too much data with a low score for a single query, you need to manually specify n to do the limit. In addition, this parameter is the same as size and from in Es, but it is introduced for compatibility with MySQL syntax, users can choose one according to their own habits, when both are used, only one will take effect, and the one specified later will overwrite the one specified first.
# from
from(Integer from)
- The query starts from the first data, which is equivalent to m in MySQL's limit (m,n).
- Example: from(10)--->From the 10th piece of data
# size
size(Integer size)
- The maximum number of data to return, equivalent to n in limit (m,n) or n in limit n in MySQL
- Example: size(10)---> return at most 10 pieces of data
提示
If you don't want too much data with a low score for a single query, you need to specify size manually to do the limit.
# minScore
minScore(Float score)
- Query the data whose score is not lower than score. If the score is lower than this value, it will not be hit.
# trackScores
trackScores();
- The default value of open calculation score is closed. The query score can be used for sorting and other scenarios.
# index
index(String indexName)
index(boolean condition, String indexName)
2
Warm tips
index(String indexName) can be specified by wrapper.index(String indexName) which index this query works on, if this query is to be queried from multiple indexes, then the index names can be separated by commas, for example, wrapper.index("index1", "indexe2"...) wrapper in the specified index name has the highest priority, if not specified, then take the name of the index configured in the entity class, if the entity class is not configured, then take the entity name in lower case as the index name of the current query For insert/delete/update and other interfaces without wrapper, if you need to specify the index name, you can directly add the index name in the corresponding interface input, see the following example:
Document document = new Document();
// omit the code that assigns a value to document
String indexName = "lahan";
insert(document,indexName);
2
3
4
# and
and(Consumer<Param> consumer)
and(boolean condition, Consumer<Param> consumer)
2
- AND
- Example: and(i -> i.eq(Document::getTitle, "Hello").eq(Document::getCreator, "Guy")) --> and (title = 'Hello' and creator = 'Guy' )
# or
or()
or(boolean condition)
2
- Splice OR Caution: Active call to or means immediately following the next method is not connected with and! (not calling or defaults to using and concatenation)
- Example: eq("Document::getId",1).or().eq(Document::getTitle, "Hello")--->id = 1 or title = 'Hello'
or(Consumer<Param> consumer)
or(boolean condition, Consumer<Param> consumer)
2
Nested OR
Example: or(i -> i.eq(Document::getTitle, "Hello").ne(Document::getCreator, "Guy")) -->or (title = 'Hello' and status ! = 'Guy' )
Special cases
Example: eq(Document::getTitle, "Hello") .and(i->i.eq(Document::getCreator, "Bob").or().eq(Document::getCreator, "Tom"))---> title="Hello" and(creator="Bob" or creator="Tom")
# filter
and and filter selection, they are similar in function, both indicate the conditions that must be met, the difference is that filter does not calculate the score, better performance, but does not support sorting based on the score.
filter()
filter(boolean condition)
2
- Splice filter Caution: Active call to filter means that the next method is immediately followed by and not connected! (not calling filter defaults to using and concatenation)
- Example: eq("Document::getId",1).filter().eq(Document::getTitle, "Hello")--->id = 1 and title ='Hello'
filter(Consumer<Param> consumer)
filter(boolean condition, Consumer<Param> consumer)
2
- Nested filter
- Example: filter(i -> i.eq(Document::getTitle, "Hello").eq(Document::getCreator, "Guy")) -->or (title = 'Hello' and status = 'Guy' )
# not
not()
not(boolean condition)
2
- Splice not Caution: Active call to not means immediately following the next method is not connected with and! (not calling not defaults to using and concatenation)
- Example: eq("Document::getId",1).not().eq(Document::getTitle, "Hello")--->id = 1 and title ! = 'Hello'
filter(Consumer<Param> consumer)
filter(boolean condition, Consumer<Param> consumer)
2
- Nested not
- Example: not(i -> i.eq(Document::getTitle, "Hello").eq(Document::getCreator, "Guy")) ---> (title ! = 'Hello' and status ! = 'Guy' )
# nested
nested(String path, Consumer<Param> consumer)
nested(String path, Consumer<Param> consumer, ScoreMode scoreMode)
nested(boolean condition, String path, Consumer<Param> consumer)
nested(boolean condition, String path, Consumer<Param> consumer, ScoreMode scoreMode)
2
3
4
- Nested queries nested
- Example: wrapper.nested("users.faqs", i -> i.eq(question, "question") ---> from faq where question = 'question' The use of scenarios is limited to nested types of queries, and there will be a separate section on nested types and parent-child types in the higher-level syntax later, so here is a brief list.