Slop问题纪录
简单的近似匹配
https://www.jianshu.com/p/485eff3d35bb
match_parse
- 匹配所有短语
- 匹配词语顺序保持一致
- 可以使用slop选择词语间隔和顺序
GET forum/article/_search
{
"query": {
"match_phrase": {
"title": {
"query": "java spark",
"slop" : 1
}
}
}
}
slop的顺序纪录
curl -X GET "localhost:9200/my_index/my_type/_search?pretty" -H 'Content-Type: application/json' -d'
{
"query": {
"match_phrase": {
"title": {
"query": "quick fox",
"slop": 1
}
}
}
}
'
slop的顺序控制时,slop的值不一定要大于短语的个数
栗子:
GET test/_search
{
"query": {
"match_phrase": {
"field": {
"query": "fox brown quick",
"slop": 2
}
}
}
}
匹配结果:
{
"took" : 0,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 2,
"relation" : "eq"
},
"max_score" : 0.1377056,
"hits" : [
{
"_index" : "test",
"_type" : "_doc",
"_id" : "OrJFAHAB2CC_oLWGufY0",
"_score" : 0.1377056,
"_source" : {
"field" : "fox quick brown"
}
},
{
"_index" : "test",
"_type" : "_doc",
"_id" : "VbIAAHAB2CC_oLWGB1eM",
"_score" : 0.10308687,
"_source" : {
"field" : "fox red blue brown quick"
}
}
]
}
}
猜测顺序:
fox brown quick
- fox quick/brown
- fox quick brown
/ 表示共用一个位置
栗子二
GET test/_search
{
"query": {
"match_phrase": {
"field": {
"query": "fox brown quick red",
"slop": 3
}
}
}
}
结果
{
"took" : 0,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 1,
"relation" : "eq"
},
"max_score" : 0.2434652,
"hits" : [
{
"_index" : "test",
"_type" : "_doc",
"_id" : "mrNbAHAB2CC_oLWGVyd0",
"_score" : 0.2434652,
"_source" : {
"field" : "fox red brown quick"
}
}
]
}
}
栗子三
GET test/_search
{
"query": {
"match_phrase": {
"field": {
"query": "fox brown quick red",
"slop": 4
}
}
}
}
结果
{
"took" : 0,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 3,
"relation" : "eq"
},
"max_score" : 0.2434652,
"hits" : [
{
"_index" : "test",
"_type" : "_doc",
"_id" : "mrNbAHAB2CC_oLWGVyd0",
"_score" : 0.2434652,
"_source" : {
"field" : "fox red brown quick"
}
},
{
"_index" : "test",
"_type" : "_doc",
"_id" : "3LNaAHAB2CC_oLWGoiVK",
"_score" : 0.2019119,
"_source" : {
"field" : "red fox brown quick"
}
},
{
"_index" : "test",
"_type" : "_doc",
"_id" : "VbIAAHAB2CC_oLWGB1eM",
"_score" : 0.17430875,
"_source" : {
"field" : "fox red blue brown quick"
}
}
]
}
}