elasticsearch(20) 数据建模
1、文件系统数据构造
PUT /fs
{
"settings": {
"analysis": {
"analyzer": {
"paths": {
"tokenizer": "path_hierarchy"
}
}
}
}
}
path_hierarchy tokenizer讲解
/a/b/c/d --> path_hierarchy -> /a/b/c/d, /a/b/c, /a/b, /a
fs: filesystem
PUT /fs/_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程序"
}
2、对文件系统执行搜索
文件搜索需求:查找一份,内容包括elasticsearch,在/workspace/projects/hellworld这个目录下的文件
GET /fs/file/_search
{
"query": {
"bool": {
"must": [
{
"match": {
"contents": "elasticsearch"
}
},
{
"constant_score": {
"filter": {
"term": {
"path": "/workspace/projects/helloworld"
}
}
}
}
]
}
}
}
{
"took": 2,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 1,
"max_score": 1.284885,
"hits": [
{
"_index": "fs",
"_type": "file",
"_id": "1",
"_score": 1.284885,
"_source": {
"name": "README.txt",
"path": "/workspace/projects/helloworld",
"contents": "这是我的第一个elasticsearch程序"
}
}
]
}
}
搜索需求2:搜索/workspace目录下,内容包含elasticsearch的所有的文件
/workspace/projects/helloworld doc1
/workspace/projects doc1
/workspace doc1
GET /fs/file/_search
{
"query": {
"bool": {
"must": [
{
"match": {
"contents": "elasticsearch"
}
},
{
"constant_score": {
"filter": {
"term": {
"path.tree": "/workspace"
}
}
}
}
]
}
}
}
- elasticsearch数据建模
- [Elasticsearch] 数据建模 - 处理关联关系(1)
- [Elasticsearch] 数据建模 - 处理关联关系
- [Elasticsearch] 数据建模 - 处理关联关系(2)
- [Elasticsearch] 数据建模 - 处理关联关系(1)
- [Elasticsearch] 数据建模 - 处理关联关系(1)
- [Elasticsearch] 数据建模 - 处理关联关系(2)
- [转] [Elasticsearch] 数据建模 - 处理关联关系(1)
- MySQL学习笔记20:数据备份与还原
- elasticsearch 大数据优化
- [IBM dW] NoSQL数据建模
- ElasticSearch大数据分布式弹性搜索引擎使用
- 浅谈数据仓库建设中的数据建模方法
- 将数据从PostgreSQL同步到Elasticsearch的经验总结
- 对:通过HBase Observer同步数据到ElasticSearch的使用情况
- elasticsearch的基础语句介绍 聚合功能很强大 可以分析数据
- NoSQL 数据建模技术
- 数据建模和数据库设计
- MongoDB实战-面向文档的数据(找到最合适的数据建模方式)
- 调整elasticsearch数据存放目录的一种快速方法