ES实践

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": {}
        }
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

浪舟子

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值