0
我试图提供搜索最终用户的类型,因为他们走哪个更像是sqlserver。我是能够实现ES查询给定的SQL场景:ngram通配符搜索弹性搜索
select * from table where name like '%peter tom%' and type != 'xyz
在ES我使用NGRAM分词器,以达到预期的效果:
PUT sample
{
"settings": {
"analysis": {
"analyzer": {
"my_ngram_analyzer": {
"tokenizer": "my_ngram_tokenizer"
}
},
"tokenizer": {
"my_ngram_tokenizer": {
"type": "nGram",
"min_gram": "2",
"max_gram": "15"
}
}
}
},
"mappings": {
"typename": {
"properties": {
"name": {
"type": "string",
"fields": {
"search": {
"type": "string",
"analyzer": "my_ngram_analyzer"
}
}
},
"type": {
"type": "string",
"index": "not_analyzed"
}
}
}
}
}
{
"query": {
"bool": {
"should": [
{
"term": {
"name.search": "peter tom"
}
}
],
"must_not": [
{
"match": {
"type": "xyz"
}
},
{
"match": {
"type": "abc"
}
}
]
}
}
}
所以,如果我的文档行像
name type
peter tomson efg
Peter tomson robert simson efg
上述查询只显示两个文件,但当我尝试输入彼得sims或彼得simson它不返回第二个文件,除非我输入彼得汤姆森罗伯特模拟人生或宠物呃汤姆森罗伯特辛普森。所以基本上我必须在彼得和辛普森之前输入下面所有的单词来获得第二个文档。有没有什么办法获得第二个文件的部分匹配。我可以使用查询匹配和“AND”操作,但仍然在单词的精确匹配。我正在寻找像彼得sims部分匹配应该给我第二行的文件。 感谢
感谢分享。帮助像我这样的初学者! –