quot; : 104541
}
} ]
}
}
显示指定字段,匹配关键字
结果格式
一旦es搜索返回给你 该链接就断开了 es并不会想MySQL之类的 一直维护一个连接
更多限制条件的搜素
curl -XGET 'localhost:9200/test/_search?pretty' -d'{
"from": 0,
"size": 1,
"_source": ["title", "allnum"],
"query": {
"match": { "title": "地铁跑酷" }
},
"sort": { "allnum": { "order": "desc" }}
}'
2、使用should
curl -XGET 'localhost:9200/test/_search?pretty' -d'{
"from": 0,
"size": 2,
"_source": ["title", "allnum"],
"query": {
"bool": {
"should": [
{ "match": { "title": "地铁跑酷" } },
{ "match": { "title": "星猫跑酷" } }
]
}
},
"sort": { "allnum": { "order": "desc" }}
}'
3、使用must/must not
curl -XGET 'localhost:9200/test/_search?pretty' -d'{
"from": 0,
"size": 2,
"_source": ["title", "allnum"],
"query": {
"bool": {
"must": [
{ "match": { "title": "地铁跑酷" } },
{ "match": { "title": "星猫跑酷" } }
]
}
},
"sort": { "allnum": { "order": "desc" }}
}'
当然 must /should/must not 可以联合起来使用
4、过滤器
curl -XPOST 'localhost:9200/test/_search?pretty' -d'{
"query": {
"filtered": {
"query": {
"match_all": {}
},
"filter": {
"range": { "allumn": { "gte": 20000, "lte": 30000 } } } }
}
}'
5、聚合
curl -XPOST 'localhost:9200/test/_search?pretty' -d'{
"size": 0,
"aggs": {
"group_by_state": {
"terms": { "field": "state" } }
}
}'
6、terms 过滤
curl -XPOST 'localhost:9200/test/_search?pretty' -d'{
"query": {
"terms": {
"status": [
304,
302
]
}
}
}
7、range 过滤
curl -XPOST 'localhost:9200/test/_search?pretty' -d'{
"query": {
"range": {
"allnum": {
"gt": 1
}
}
}
}
范围操作符包含:
-
gt :: 大于
-
gte:: 大于等于
-
lt :: 小于
-
lte:: 小于等于
8、exists 和 missing 过滤
exists 和 missing 过滤可以用于查找文档中是否包含指定字段或没有某个字段,类似于SQL语句中的IS_NULL条件
{
"exists": {
"field": "title"
}
}
9、bool 过滤
bool 过滤可以用来合并多个过滤条件查询结果的布尔逻辑,它包含一下操作符:
- must :: 多个查询条件的完全匹配,相当于 and。
- must_not :: 多个查询条件的相反匹配,相当于 not。
- should :: 至少有一个查询条件匹配, 相当于 or。
这些参数可以分别继承一个过滤条件或者一个过滤条件的数组:
{
"bool": {
"must": { "term": { "folder": "inbox" }},
"must_not": { "term": { "tag": "spam" }},
"should": [
{ "term": { "starred": true }},
{ "term": { "unread": true }}
]
}
}
七、中文分词
创建索引