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" : "可愛的大象"
      }
    } ]
  }
}
發佈了47 篇原創文章 · 獲贊 6 · 訪問量 3萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章