1.term精確查找,實際上是包含的意思
用法一:與bool,filter使用
GET ZF_en/_search
{
"query": {
"bool": {
"filter": {
"term": {
"grids": "604"
}
}
}
}
}
用法二:直接term查詢
GET ZF_en/_search
{
"query": {
"term": {
"grids": {
"value": "604"
}
}
}
}
2._bulk 批量寫入,注意,必須指定_id,須換行
如果_id存在,執行的是update操作
3.組合查詢,bool(布爾)過濾器
一個bool(布爾)過濾器由三部分組成:
{
"bool" : {
"must" : [],
"should" : [],
"must_not" : [],
}
}
must:所有的語句都 必須(must) 匹配,與 AND 等價。
should:至少有一個語句要匹配,與 OR 等價
must_not:所有的語句都 不能(must not) 匹配,與 NOT 等價。
無嵌套多條件組合查詢:
查詢性別是男或者年齡是27歲,但性別不是女的用戶
bool與term精確查找:
查詢年齡是27歲的用戶
注意:精確查找必須與filter一起使用
4.查找多個精確值:
terms多個值精確搜索,查找條件改爲數組
查找年齡爲25或27歲的用戶
5.範圍查詢
range,類似於sql中的between and,可選範圍表達式:
gt: > 大於(greater than)
lt: < 小於(less than)
gte: >= 大於或等於(greater than or equal to)
lte: <= 小於或等於(less than or equal to)
數字範圍查找,查詢年齡25到27歲的用戶
日期範圍查找,查詢1992年出生的用戶
字符串範圍查詢
在倒排索引中的詞項就是採取字典順序(lexicographically)排列的,這也是字符串範圍可以使用這個順序來確定的原因。
注意如果查詢字段不支持按字母排序,查詢無結果
6.空值查詢
exists,類似sql中的is not null
查詢tags不爲空的
missing,類似sql中的is null