introduce :
- 测试整个集群使用的分词器 只需要在一个节点安装即可
- 在同一个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" : "可爱的大象"
}
} ]
}
}