index test
的 mapping 定义:
"content": {
"type": "text",
"analyzer": "ik_smart"
},
"title": {
"type": "text",
"analyzer": "ik_smart"
}
测试分词:
http://127.0.0.1:9200/_analyze
提交参数:
{
"text": "中国美国英国",
"analyzer": "ik_smart"
}
返回
{
"tokens": [
{
"token": "中国",
"start_offset": 0,
"end_offset": 2,
"type": "CN_WORD",
"position": 0
},
{
"token": "美国",
"start_offset": 2,
"end_offset": 4,
"type": "CN_WORD",
"position": 1
},
{
"token": "英国",
"start_offset": 4,
"end_offset": 6,
"type": "CN_WORD",
"position": 2
}
]
}
_search 测试一下索引 test
get body
{
"size": 20,
"query": {
"match": {
"content": "广州人"
}
}
}
返回:
{
"took": 0,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 1,
"max_score": 0.84268904,
"hits": [
{
"_index": "dcc-speechcrafts",
"_type": "dcc-speechcraft",
"_id": "AXIyjmXuVhRXxkRgwNlT",
"_score": 0.84268904,
"_source": {
"title": "",
"content": "qefdygyrfh 广州人"
}
}
]
}
}
第二次_search 测试一下
get body
{
"size": 20,
"query": {
"match": {
"content": "广州"
}
}
}
返回:
{
"took": 1,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 0,
"max_score": null,
"hits": []
}
}
问题,我那条记录内容包含广州人
这三个字,为什么分别用广州人
和广州
两个词去查询,一次有结果,一次没结果呀?按道理用广州
去查询应该也是返回一样的结果的呀,这什么问题?
elasticsearch 5.6.16
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.