在ES的全文搜索时,关于intervals的使用记录
重点关注下,match、all_of、any_of的使用方式,以及对“max_gaps”的理解
直接上代码:
GET /test/_search
{
"query": {
"intervals": {
"description": {
"all_of": {
"ordered": true,
"intervals": [
{
"match": {
"query": "Detects",
"max_gaps": 0,
"ordered": true
}
},
{
"all_of": {
"intervals": [
{
"match":{
"max_gaps":0,
"query":"library"
}
},
{
"match": {
"max_gaps":0,
"query": "the presence "
}
},
{/////////❶///////////
"match":{
"max_gaps":6,
"ordered":true,
"query":"Avast library"
}
///////////////////
}
]
}
}
]
}
}
}
}
}
注解
all_of和any_of区别:前者需要全部匹配,后者只任一匹配即可
❶ “match”:{
“max_gaps”:3,
“ordered”:true,
“query”:“Avast library”
}query:查询匹配内容
ordered:表示query中的两个词,是否有顺序要求,如果为true,文档中的顺序必须一致
max_gaps:表示query中词的间隔,如果为6表示,可匹配 Detects xxx Avast one two three library,如果Detects xxx Avast one two three four library无法匹配,超出限制