导入数据
1.创建索引——put 索引名字
author、title、id :text类型(字符串)paragraphs :数组类型
PUT song
{
"mappings": {
"properties": {
"author":{
"type": "text"
},
"title":{
"type": "text"
},
"paragraphs":{
"index": "true",
"type": "keyword"
},
"id":{
"type": "text"
}
}
}
}
执行结果
2.插入数据——put 索引/_doc/数字
PUT song/_doc/1
{
"author": "宋太祖",
"paragraphs": [
"欲出未出光辣達,千山萬山如火發。",
"須臾走向天上來,逐却殘星趕却月。"
],
"title": "日詩",
"id": "08e41396-2809-423d-9bbc-1e6fb24c0ca1"
}
查询数据
1.全局查询——GET 索引/_search
GET song/_search
{
"query": {
"match_all": {}
}
}
查询结果
2.判断索引是否存在——head
GET song/_count
查询成功
查询失败
统计数据
1.分词统计
创建索引
创建索引时添加字段"fielddata": "true"
例如
PUT song
{
"mappings": {
"properties": {
"author":{
"type": "text"
},
"title":{
"type": "text"
},
"paragraphs":{
"analyzer": "ik_max_word",
"type": "text",
"fielddata": "true"
},
"id":{
"type": "text"
}
}
}
}
字段查询
在插入完数据后,进行分词查询
GET song/_search?pretty
{
"size" : 0,
"aggs" : {
"messages" : {
"terms" : {
"size" : 10,
"field" : "paragraphs"
}
}
}
}
查询结果
|