1.创建accounts索引库
PUT /accounts
{
"mappings": {
"person": {
"properties": {
"user": {
"type": "text",
"analyzer": "ik_max_word",
"search_analyzer": "ik_max_word"
},
"title": {
"type": "text",
"analyzer": "ik_max_word",
"search_analyzer": "ik_max_word"
},
"desc": {
"type": "text",
"analyzer": "ik_max_word",
"search_analyzer": "ik_max_word"
}
}
}
}
}
PUT my_index
{
"settings": {
"analysis": {
"filter": {
"autocomplete_filter": {
"type": "edge_ngram",
"min_gram": 1,
"max_gram": 20
}
},
"analyzer": {
"autocomplete": {
"type": "custom",
"tokenizer": "standard",
"filter": [
"lowercase",
"autocomplete_filter"
]
}
}
}
},
"mappings": {
"my_type": {
"properties": {
"text": {
"type": "text",
"analyzer": "autocomplete",
"search_analyzer": "standard"
}
}
}
}
}
PUT my_index/my_type/1
{
"text": "Quick Brown Fox"
}
GET my_index/_search
{
"query": {
"match": {
"text": {
"query": "Quick Br",
"operator": "and"
}
}
}
}
1.创建一个博客索引库blog_index,自定义分析器
分片数非3,副本分片数为1
分析器需求:
(1)对html进行过滤
(2)使用中文分词
(3)设置标记过滤器,停用哎,了,的,额
http://192.168.5.128:9200/blog_index
{
"settings": {
"number_of_shards": 3,
"number_of_replicas": 1,
"analysis": {
"filter": {
"my_stopwords": {
"type": "stop",
"stopwords": [
"哎",
"了",
"的",
"额"
]
}
},
"analyzer": {
"my_analyzer": {
"type": "custom",
"char_filter": [
"html_strip"
],
"tokenizer": "ik_max_word",
"filter": [
"lowercase",
"my_stopwords"
]
}
}
}
}
}
2.存入数据
{
"title": "《信南山》",
"date": "2017-12-5",
"article": "<h2>《信南山》</h2><p>年代: 先秦 作者: 诗经</p><p>信彼南山,维禹甸之。<br/>畇畇原隰,曾孙田之。<br/>我疆我理,南东其亩。</p><p>上天同云,雨雪雰雰,益之以霡霂。<br/>既优既渥,既沾既足,生我百谷。</p><p>疆埸翼翼,黍稷彧彧。<br/>曾孙之穑,以为酒食。<br/>畀我尸宾,寿考万年。</p><p>中田有庐,疆埸有瓜。<br/>是剥是菹,献之皇祖。<br/>曾孙寿考,受天之祜。</p><p>祭以清酒,从以骍牡,享于祖考。<br/>执其鸾刀,以启其毛,取其血膋。</p><p>是烝是享,苾苾芬芬。<br/>祀事孔明,先祖是皇。<br/>报以介福。万寿无疆。</p><p><br/></p>",
"issure": "马福孝"
}
3.条件查询
GET _search
{
"query": {
"bool":{
"filter":{
"range":{
"age":{"gt":30}
}
},
"must":{
"match": {
"last_name": "Smith"
}
}
}
}
}
4.高亮显示查询结果
GET _search
{
"query": {
"match_phrase":{
"article": "引用"
}
},
"highlight":{
"fields": {
"article": {}
}
}
}