1.关键字约定:
index 索引 type 类型 token 表征 filter 过滤器 analyser 分析器
终端测试
curl 'http://localhost:9200/?pretty'
节点客户端
传输客户端
curl -X
curl -XGET 'http://localhost:9200/_count?pretty' -d '
{
"query": {
"match_all": {}
}
}
索引、搜索、聚合
存储数据的过程 叫做索引
索引 类型 文档 字段
索引(名词)
索引(动词)
倒排索引
检索文档:
GET /megacorp/employee/1 DELETE 方法删除文档 使用 HEAD 方法检查
GET /megacorp/employee/_search
轻量级查询
GET /megacorp/employee/_search?q=last_name:Smith
DSL语句查询
GET /megacorp/employee/_search { "query" : { "match" : { "last_name" : "Smith" } } }GET /megacorp/employee/_search { "query":{ "filtered":{ "filter":{ "range":{ "age":{ "gt":30 } } }, "query":{ "match":{ "last_name":"smith" } } } } }
全文搜索
GET /megacorp/employee/_search { "query" : { "match" : { "about" : "rock climbing" } } } 返回结果 有相关性评分
短语搜索
GET /megacorp/employee/_search { "query":{ "match_phrase":{ "about":"rock climbing" } } }
高亮搜索
GET /megacorp/employee/_search { "query" : { "match_phrase" : { "about" : "rock climbing" } }, "highlight": { "fields" : { "about" : {} } } }
获取员工共同爱好
GET /megacorp/employee/_search { "aggs": { "all_interests": { "terms": { "field": "interests" } } } }
GET /megacorp/employee/_search { "query": { "match": { "last_name": "smith" } }, "aggs": { "all_interests": { "terms": { "field": "interests" } } } }
每种兴趣下员工的平均年龄
GET /megacorp/employee/_search { "aggs" : { "all_interests" : { "terms" : { "field" : "interests" }, "aggs" : { "avg_age" : { "avg" : { "field" : "age" } } } } } }
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)