es 分词器使用简介

introduce :

  1. 测试整个集群使用的分词器 只需要在一个节点安装即可
  2. 在同一个type下 不同字段可以设置不同的分词器

示例如下:

创建index

curl -XPUT http://spark2:9200/test_ik?pretty

添加mapping
对不同的字段分别使用不同的分词器

curl -XPOST http://spark2:9200/test_ik/fulltext/_mapping?pretty -d'{
  "fulltext": {
    "_all": {
      "analyzer": "ik_max_word",
      "search_analyzer": "ik_max_word",
      "term_vector": "no",
      "store": "false"
    },
    "properties": {
      "content": {
        "type": "string",
        "analyzer": "ik_max_word",
        "search_analyzer": "ik_max_word",
        "include_in_all": "true",
        "boost": 8
      },
      "noik": {
        "type": "string",
        "analyzer": "standard"
      }
    }
  }
}'

添加数据

curl -XPOST http://spark2:9200/test_ik/fulltext/1?pretty -d '{
  "content": "美国留给伊拉克的是个烂摊子吗",
  "noik": "可爱的大象"
}'

curl -XPOST http://spark2:9200/test_ik/fulltext/2?pretty  -d '{
  "content": "公安部:各地校车将享最高路权",
  "noik": "可爱的小鸟"
}'

curl -XPOST http://spark2:9200/test_ik/fulltext/3?pretty  -d '{
  "content": "中韩渔警冲突调查:韩警平均每天扣1艘中国渔船",
  "noik": "大象"
}'

curl -XPOST http://spark2:9200/test_ik/fulltext/4?pretty -d '{
  "content": "中国驻洛杉矶领事馆遭亚裔男子枪击 嫌犯已自首",
  "noik": "小鸟"
}'

仅对添加的第一条数据 测试说明

匹配noik 输入象

curl -XPOST http://spark2:9200/test_ik/fulltext/_search?pretty  -d '{
>   "query": {
>     "term": {
>       "noik": "象"
>     }
>   }
> }'
{
  "took" : 3,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "failed" : 0
  },
  "hits" : {
    "total" : 1,
    "max_score" : 0.13424811,
    "hits" : [ {
      "_index" : "test_ik",
      "_type" : "fulltext",
      "_id" : "1",
      "_score" : 0.13424811,
      "_source" : {
        "content" : "美国留给伊拉克的是个烂摊子吗",
        "noik" : "可爱的大象"
      }
    } ]
  }
}

匹配noik 输入大象


[guolin@spark1 ik]$ curl -XPOST http://spark2:9200/test_ik/fulltext/_search?pretty  -d '{
>   "query": {
>     "term": {
>       "noik": "大象"
>     }
>   }
> }'
{
  "took" : 3,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "failed" : 0
  },
  "hits" : {
    "total" : 0,
    "max_score" : null,
    "hits" : [ ]
  }
}

匹配content

curl -XPOST http://spark2:9200/test_ik/fulltext/_search?pretty  -d '{
>   "query": {
>     "match": {
>       "content": "烂摊子"
>     }
>   }
> }'
{
  "took" : 7,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "failed" : 0
  },
  "hits" : {
    "total" : 1,
    "max_score" : 1.2274113,
    "hits" : [ {
      "_index" : "test_ik",
      "_type" : "fulltext",
      "_id" : "1",
      "_score" : 1.2274113,
      "_source" : {
        "content" : "美国留给伊拉克的是个烂摊子吗",
        "noik" : "可爱的大象"
      }
    } ]
  }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值