put data_index
{
"mappings":{
"data_index":{
"properties": {
"docId": {
"type": "text"
},
"taskId": {
"type": "text",
"fielddata" : true
},
"title": {
"type": "text",
"index":true,
"analyzer":"ik_max_word",
"search_analyzer": "ik_smart"
},
"summary": {
"type": "text",
"index":true,
"analyzer":"ik_max_word",
"search_analyzer": "ik_smart"
},
"releaseTime": {
"type": "date",
"format": "yyyy-MM-dd HH:mm:ss"
},
"siteName": {
"type": "text"
},
"siteUrl": {
"type": "text"
},
"siteDetailUrl": {
"type": "text"
},
"content": {
"type": "text",
"analyzer":"ik_smart"
},
"contentSentenceSplit": {
"type": "text",
"analyzer":"ik_smart"
},
"md5Code": {
"type": "keyword"
},
"pageId": {
"type": "text"
},
"pointsFavorite": {
"type": "long"
},
"pointsReading": {
"type": "long"
},
"pointsPraise": {
"type": "long"
},
"deleteFlag": {
"type": "text"
},
"userId": {
"type": "text",
"fielddata":true
},
"monitorSolutionId": {
"type": "keyword"
},
"accountId": {
"type": "keyword"
},
"orgCode": {
"type": "text"
},
"iframeStatus": {
"type": "text"
},
"updateTime": {
"type": "date",
"format": "yyyy-MM-dd HH:mm:ss"
},
"createTime": {
"type": "date",
"format": "yyyy-MM-dd HH:mm:ss"
}
}
}
}
}
data_index:索引名
data_type:类型
1.查询分词结果
GET /_analyze
{
"text":"发明专利",
"analyzer": "ik_max_word"
}
2.词项查询
GET data_index/data_type/_search
{
"_source": {
"includes": ["praiseType","content"]
},
"query": {
"term": {
"mediaType": {
"value": "3"
}
}
},
"from": 0,
"size": 20
}
3.复合查询
GET data_index/data_type/_search
{
"_source": {
"includes": ["praiseType","content"]
},
"query": {
"bool": {
"must": [
{
"term": {
"mediaType": {
"value": "3"
}
}
}
],
"must_not":[
{
"term": {
"deleteFlag": {
"value": "1"
}
}
}
]
}
},
"from": 0,
"size": 20
}
4.聚合
GET data_index/data_type/_search
{
"query": {
"term": {
"crawlerType": {
"value": "1"
}
}
},
"aggs": {
"mediaType": {
"terms": {
"field": "mediaType"
}
}
},
"size": 0
}
GET data_index/data_type/_search
{
"aggs": {
"mediaType": {
"terms": {
"field": "mediaType"
}
}
},
"size": 0
}
查询更新
POST data_index/_update_by_query
{
"script":{
"source":"ctx._source.praiseType = '2'",
"lang":"painless"
},
"query": {
"bool": {
"must_not":[
{
"exists": {
"field":"praiseType"
}
}
]
}
}
}
GET data_index/data_type/_search
{
"_source": {
"includes": ["praiseType"]
},
"script":{
"inline":"ctx.source.praiseType" = params.praiseType,
"lang":"painless",
"params":{"praiseType":"2"}
},
"query": {
"bool": {
"must":[
{
"term": {
"md5Code":"b42ca83c7eb3e2c4b5c95db90edffc51"
}
}
]
}
},
"from": 0,
"size": 20
}
POST twitter/_update_by_query
{
"script": {
"source": "ctx._source.likes++",
"lang": "painless"
},
"query": {
"term": {
"user": "kimchy"
}
}
}
索引别名设置:
POST /_aliases
{
"actions": [
{ "remove": { "index": "old_index", "alias": "data_index" }},
{ "add": { "index": "new_index", "alias": "data_index" }}
]
}