1、保存数据
PUT /megacorp/employee/2
{
"first_name" : "Jane",
"last_name" : "Smith",
"age" : 32,
"about" : "I like to collect rock albums",
"interests": [ "music" ]
}
PUT /megacorp/employee/3
{
"first_name" : "Douglas",
"last_name" : "Fir",
"age" : 35,
"about": "I like to build cabinets",
"interests": [ "forestry" ]
}
2、设置maping
PUT /data/http_record/_mapping?pretty
{
"http_record":{
"properties":{
"ip": {
"type": "ip"
},
"username": {
"type": "text"
},
"timestamp": {
"type": "long"
},
"host": {
"type": "text",
"index": "true"
},
"url":{
"type":"text",
"index": "true"
},
"imei":{
"type":"text",
"index":"true"
},
"phoneno":{
"type":"text"
},
"user_agent":{
"type":"text",
"index":"true"
}
}
}
}
3、条件查询
GET /data/http_record/_search/
{
"query": { "term": {"host":"www.mogujie.com"} },//查询host为www.mogujie.com的数据
"_source": ["url", "host"]//source部分只显示url与host
}
4、全文检索
GET /data/http_record/_search
{
"query" : {
"match_phrase" : {
"url" : "imei"//搜索url字段中包含imei的记录
}
}
}
5、聚合操作(对host字段进行聚合操作)
GET /data/http_record/_search
{
"size" :0,
"aggs" : {
"hosts" : {
"terms" : {
"field" : "host"
}
}
}
}
elastic search6中文官方文档有详细介绍:https://www.elastic.co/guide/cn/elasticsearch/guide/current/index.html