mta*_*riq 13 search tokenize analyzer elasticsearch
搜索包含空格的名称(文本),给我带来问题,我的映射类似于
"{"user":{"properties":{"name":{"type":"string"}}}}"
Run Code Online (Sandbox Code Playgroud)
理想情况下它应返回并按如下方式对结果进行排名
1) Bring on top names that exact match the search term (highest score)
2) Names that starts with the search term (high score)
3) Names that contains the exact search term as substring (medium score)
4) Names that contains any of the search term token (lowest score)
Run Code Online (Sandbox Code Playgroud)
示例对于elasticsearch中的以下名称
Maaz Tariq
Ahmed Maaz Tariq
Maaz Sheeba
Maaz Bin Tariq
Sana Tariq
Maaz Tariq Ahmed
Run Code Online (Sandbox Code Playgroud)
搜索"Maaz Tariq",结果应按以下顺序排列
Maaz Tariq (highest score)
Maaz Tariq Ahmed (high score)
Ahmed Maaz Tariq (medium score)
Maaz Bin Tariq (lowest score)
Maaz Sheeba (lowest score)
Sana Tariq (lowest score)
Run Code Online (Sandbox Code Playgroud)
任何人都可以指出我如何使用和使用哪种分析仪?以及如何对名称的搜索结果进行排名?
Iva*_*ldi 10
您可以使用多字段类型,bool查询和自定义提升因子查询来解决此问题.
制图:
{
"mappings" : {
"user" : {
"properties" : {
"name": {
"type": "multi_field",
"fields": {
"name": { "type" : "string", "index": "analyzed" },
"exact": { "type" : "string", "index": "not_analyzed" }
}
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
查询:
{
"query": {
"bool": {
"must": [
{
"match": {
"name": "Maaz Tariq"
}
}
],
"should": [
{
"custom_boost_factor": {
"query": {
"term": {
"name.exact": "Maaz Tariq"
}
},
"boost_factor": 15
}
},
{
"custom_boost_factor": {
"query": {
"prefix": {
"name.exact": "Maaz Tariq"
}
},
"boost_factor": 10
}
},
{
"custom_boost_factor": {
"query": {
"match_phrase": {
"name": {
"query": "Maaz Tariq",
"slop": 0
}
}
},
"boost_factor": 5
}
}
]
}
}
}
Run Code Online (Sandbox Code Playgroud)
编辑:
正如javanna指出的那样,custom_boost_factor不需要.
查询没有custom_boost_factor:
{
"query": {
"bool": {
"must": [
{
"match": {
"name": "Maaz Tariq"
}
}
],
"should": [
{
"term": {
"name.exact": {
"value": "Maaz Tariq",
"boost": 15
}
}
},
{
"prefix": {
"name.exact": {
"value": "Maaz Tariq",
"boost": 10
}
}
},
{
"match_phrase": {
"name": {
"query": "Maaz Tariq",
"slop": 0,
"boost": 5
}
}
}
]
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10010 次 |
| 最近记录: |