弹性搜索优先搜索以搜索词开头的结果
Elastic Search Prioritize search results that begin with the search term
我需要优先显示以搜索词开头的搜索结果。我用了"match_phrase_prefix"。我用了"match_phrase_prefix"。但是没有用。
详情:
查询
GET /test/products/_search?pretty
{
"query": {
"match_phrase_prefix": {
"title": "iphone 5c"
}
}
}
结果
"_score": 10.440153
title": "Capa de Tpu para Iphone 5c Modelo Apple + Película"
"_score": 9.981493,
"title": "Capa Bumper Iphone 5C + Pelicula",
"_score": 8.610232
"title": "Pelicula Protetora para Iphone 5C Transparente"
"_score": 5.154923,
"title": "iPhone 5c Apple 8GB com Tela de 4”, iOS7, Câmera 8MP, Touch Screen, Wi-Fi, 3G/4G, GPS, MP3 e Bluetooth - Rosa"
"_score": 5.154923
"title": "iPhone 5c Apple 8GB com Tela de 4”, iOS7, Câmera 8MP, Touch Screen, Wi-Fi, 3G/4G, GPS, MP3 e Bluetooth - Branco"
"_score": 5.154923
"title": "iPhone 5c Apple 8GB com Tela de 4”, iOS7, Câmera 8MP, Touch Screen, Wi-Fi, 3G/4G, GPS, MP3 e Bluetooth - Preto"
映射
"mappings": {
"products": {
"properties": {
"title": {
"type": "string",
"analyzer": "brazilian"
}
}
}
}
In this example I need the first result is the device (Iphone 5c)
使用分析器导致标记化问题。在下面查看您的文档字段是如何被标记化的。
您需要使用关键字分词器。
curl -XGET 'localhost:9200/test/_analyze?analyzer=standard&pretty' -d 'Capa Bumper Iphone 5C' | grep token
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 532 100 511 100 21 32800 1347 --:--:-- --:--:-- --:--:-- 34066
"tokens" : [ {
"token" : "capa",
"token" : "bumper",
"token" : "iphone",
"token" : "5c",
在您的映射中添加关键字分词器:
我需要优先显示以搜索词开头的搜索结果。我用了"match_phrase_prefix"。我用了"match_phrase_prefix"。但是没有用。
详情:
查询
GET /test/products/_search?pretty { "query": { "match_phrase_prefix": { "title": "iphone 5c" } } }
结果
"_score": 10.440153 title": "Capa de Tpu para Iphone 5c Modelo Apple + Película"
"_score": 9.981493, "title": "Capa Bumper Iphone 5C + Pelicula", "_score": 8.610232 "title": "Pelicula Protetora para Iphone 5C Transparente" "_score": 5.154923, "title": "iPhone 5c Apple 8GB com Tela de 4”, iOS7, Câmera 8MP, Touch Screen, Wi-Fi, 3G/4G, GPS, MP3 e Bluetooth - Rosa" "_score": 5.154923 "title": "iPhone 5c Apple 8GB com Tela de 4”, iOS7, Câmera 8MP, Touch Screen, Wi-Fi, 3G/4G, GPS, MP3 e Bluetooth - Branco" "_score": 5.154923 "title": "iPhone 5c Apple 8GB com Tela de 4”, iOS7, Câmera 8MP, Touch Screen, Wi-Fi, 3G/4G, GPS, MP3 e Bluetooth - Preto"
映射
"mappings": { "products": { "properties": { "title": { "type": "string", "analyzer": "brazilian" } } } }
In this example I need the first result is the device (Iphone 5c)
使用分析器导致标记化问题。在下面查看您的文档字段是如何被标记化的。
您需要使用关键字分词器。
curl -XGET 'localhost:9200/test/_analyze?analyzer=standard&pretty' -d 'Capa Bumper Iphone 5C' | grep token
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 532 100 511 100 21 32800 1347 --:--:-- --:--:-- --:--:-- 34066
"tokens" : [ {
"token" : "capa",
"token" : "bumper",
"token" : "iphone",
"token" : "5c",
在您的映射中添加关键字分词器: