如何建立恰當(dāng)?shù)乃饕Y(jié)點(diǎn)
{
"mappings": {
"data": {
"properties": {
"answer_id": {
"type": "long"
},
"content": {
"type": "text",
"analyzer": "html_analyze"
},
"question_id": {
"type": "long"
},
"title": {
"type": "text",
"analyzer": "html_analyze"
},
"authority":{ //權(quán)限數(shù)組[1,2,3,4]
"type": "byte"
}
}
}
},
"settings": {
"analysis": {
"filter": { //定義一個(gè)同義詞過(guò)濾器
"local_synonym": {
"type": "synonym",
"synonyms_path": "analysis/synonym.txt"
}
},
"analyzer": {
"html_analyze": { //定義一個(gè)html標(biāo)簽過(guò)濾的分詞器
"filter": [
"local_synonym"
],
"char_filter": [
"my_char_filter"
],
"type": "custom",
"tokenizer": "ik_max_word"
}
},
"char_filter": {
"my_char_filter": {
"escaped_tags": [],
"type": "html_strip"
}
}
}
}
}
上傳到ElasticSearch的數(shù)據(jù)格式如下:
{
"answer_id": 1,
"content": "內(nèi)容",
"question_id": 2,
"title": "標(biāo)題",
"authority": [1,2,3,4] //權(quán)限有數(shù)組控制飘千,每個(gè)user有自己對(duì)應(yīng)的權(quán)限
}
如何使用高亮并且進(jìn)行權(quán)限過(guò)濾搜索
{
"from": 0,
"size": 10,
"query":{
"bool": {
"must":{
"multi_match": {
"query": "測(cè)試",
"type": "best_fields",
"fields": ["title^2", "content"],
"tie_breaker": 0.3
}
},
"filter": {
"term": {
"authority": "1" // 過(guò)濾出權(quán)限為1的結(jié)果集
}
}
}
},
"highlight": {
"pre_tags": ["<span style='color: rgb(230, 0, 0);'>"],
"post_tags": ["</span>"],
"fields": {
"title": {"number_of_fragments":0},
"content": {"fragment_size": 100}
}
}
}