elasticsearch数据建模
2018-07-07 15:18
162 查看
类似于mysql数据库主外键,三范式 ,先根据条件查询到主键,再根据主键查询到对应的数据
PUT /website/users/1 { "name" : "小鱼儿", "email" : "1690780260@QQ.com", "birthday" : "1997-08-03" } PUT /website/blog/1 { "title" : "小鱼儿的第一篇博客", "content" : "这是我的第一篇博客,开通了", "userId" : 1 } GET /website/users/_search { "query": { "constant_score": { "filter": { "terms": { "name.keyword": [ "小鱼儿" ] } } } } } GET /website/blog/_search { "query": { "constant_score": { "filter": { "term": { "userId": 1 } } } } }
每个博主下的前五篇博客
GET /website/blogs/_search { "size": 0, "aggs": { "group_by_name": { "terms": { "field": "userInfo.userName.keyword" }, "aggs": { "top_title": { "top_hits": { //控制为前5篇博客 "_source": { //控制搜索结果中显示那些内容,这里只包含title,也就是只显示title "include": "title" }, "size": 5 } } } } } }
文件系统建模
//自定义分词器,并建立索引 PUT /fs { "settings": { "analysis": { "analyzer": { "paths" : { "tokenizer" : "path_hierarchy" } } } }, "_mapping" : { "file" : { "properties" : { "name" : { "type" : "keyword" }, "path" : { "type" : "keyword", "fields" : { "tree" : { "type" : "text", "analyzer" : "paths" } } } } } } } //填充数据 PUT /fs/file/1 { "name": "README.txt", "path": "/workspace/projects/helloworld", "contents": "这是我的第一个elasticsearch程序" } //搜索指定目录下文件内容包含elasticserch的文件 GET /fs/file/_search { "query": { "bool": { "must": [ {"match": { "contents": "elasticsearch" }}, {"constant_score": { "filter": { "match": { "path": "/workspace/projects/helloworld" } } }} ] } } } //因为path的分词器是path_hierarchy 所以可以使用部分路径进行搜素 GET /fs/file/_search { "query": { "bool": { "must": [ {"match": { "contents": "elasticsearch" }}, {"constant_score": { "filter": { "match": { "path": "/workspace" } } }} ] } } }
elasticsearch 中 index级别的锁
GET /fs/file/_search PUT /fs/block/global/_create {} //加锁 //如果在此时间点,如果在另一个客户端进行put,或者是post操作,是会报错的 POST /fs/file/1/_update { "doc" : { "name" : "README1.txt" } } DELETE /fs/block/global //解锁阅读更多
相关文章推荐
- [Elasticsearch] 数据建模 - 处理关联关系(1)
- [Elasticsearch] 数据建模 - 处理关联关系(2)
- [Elasticsearch] 数据建模 - 处理关联关系(1)
- [Elasticsearch] 数据建模 - 处理关联关系(2)
- [转] [Elasticsearch] 数据建模 - 处理关联关系(1)
- [Elasticsearch] 数据建模 - 处理关联关系(1)
- [Elasticsearch] 数据建模 - 处理关联关系
- 通过HBase Observer同步数据到ElasticSearch
- 数据仓库专题(7)-维度建模10大基本原则
- 利用python调用elasticsearch-api来分析数据并作图进行日报邮件发送
- UML建模之数据建模(Data Model Diagram)
- 记录ElasticSearch6.2.4+Jest开发笔记(3)- 数据导入ES
- 大数据——hadoop1.2.1+hbase0.94.11+nutch2.2.1+elasticsearch0.90.5安装配置攻略(中集)
- NoSQL数据建模
- elasticsearch__2__java操作之数据搜索查询
- MongoDB数据导入Elasticsearch
- elasticsearch更新数据
- 使用Mapreduce将hbase表中的数据全量导入ElasticSearch
- 数据仓库建模点滴
- 数据仓库建模与ETL实践技巧