我的标记器
"tokenizer": {
"my_tokenizer": {
"type": "edge_ngram",
"min_gram": 1,
"max_gram": 10,
"token_chars": [
"letter",
"digit"
]
}
我正试图基于此字段搜索值,但这里的问题是,无论何时,我都希望基于标记进行搜索,例如,假设我使用s标记进行搜索,那么我应该得到与s匹配或开始于s的项,现在如果我使用sp进行搜索,我希望得到从sp开始的项,放弃其他项,我只想得到以sp开始的值并放弃所有,我没有得到是我的查询错误还是我使用的过滤器错误有人能帮我这个吗
{
"query": {
"bool": {
"must": [
{
"multi_match": {
"query": "PRODUCT",
"fields": [
"hierarchy_name",
"attribute_name"
]
}
},
{
"multi_match": {
"query": "SUB_FAMILY",
"fields": [
"hierarchy_name",
"attribute_name"
]
}
},
{
"match": {
"item_pk": "SP"
}
}
]
}
}
}
此查询的输出为
"hits": [
{
"_index": "logs_datas",
"_type": "_doc",
"_id": "H1PfEnkBQXpKNrJSp8bV",
"_score": 9.418445,
"_source": {
"message": "PRODUCT,SUB_FAMILY,SPRINHO2H",
"path": "/home/niteshb/elasticsearchDatas.csv",
"hierarchy_name": "PRODUCT",
"@version": "1",
"@timestamp": "2021-04-27T10:28:37.578Z",
"host": "ewiglp71",
"item_pk": "SPRINHO2H",
"attribute_name": "SUB_FAMILY"
}
},
{
"_index": "logs_datas",
"_type": "_doc",
"_id": "y1PfEnkBQXpKNrJSp8XQ",
"_score": 5.3059187,
"_source": {
"message": "PRODUCT,SUB_FAMILY,SCMLPLWVI",
"path": "/home/niteshb/elasticsearchDatas.csv",
"hierarchy_name": "PRODUCT",
"@version": "1",
"@timestamp": "2021-04-27T10:28:37.577Z",
"host": "ewiglp71",
"item_pk": "SCMLPLWVI",
"attribute_name": "SUB_FAMILY"
}
},
{
"_index": "logs_datas",
"_type": "_doc",
"_id": "zFPfEnkBQXpKNrJSp8XQ",
"_score": 5.3059187,
"_source": {
"message": "PRODUCT,SUB_FAMILY,SSVRKEN2Z",
"path": "/home/niteshb/elasticsearchDatas.csv",
"hierarchy_name": "PRODUCT",
"@version": "1",
"@timestamp": "2021-04-27T10:28:37.579Z",
"host": "ewiglp71",
"item_pk": "SSVRKEN2Z",
"attribute_name": "SUB_FAMILY"
}
}
}
]
}
}
1条答案
按热度按时间a11xaf1n1#
自从
min_gram
为1,因此生成的令牌SCMLPLWVI
将如果你想从
sp
然后您需要修改您的标记器更新1:
您可以使用match\u bool\u前缀来搜索以
s
或者sp
添加工作示例索引Map:
搜索查询1:
搜索结果将是
搜索查询2:
搜索结果: