弹性搜索单词建议
Elastic Search word suggestion
我们希望弹性搜索建议在索引中找到的词。我们正在使用版本:5.6.4.
如果我键入 "head",它应该建议 "headquarters",这是在索引中找到的一个词。最好它应该按出现次数对建议进行排序。
我试过几个教程,但它们都是 return 整个内容项而不是单词本身。我使用文档得出的最接近结果如下:
GET test_content/_search?pretty
{
"suggest": {
"text": "head",
"my-suggestion": {
"term": {
"field":"autocomplete"
}
}
}
}
但它没有给出任何结果,直到我输入:"headquarte"。
当我键入 "lead" 时,我期望 "leadership",但得到的结果是:"land"。错别字纠正可能很好,但不是我目前想要的。我首先想要获得一个稳定的工作单词建议功能,稍后可能包括拼写错误更正。
我也试过 edgeNGram
过滤器,但没有得到任何正确的结果。 whitespace
过滤器现在应该没问题。前缀搜索对我来说没问题。
配置:
PUT test_content
{
"settings": {
"analysis": {
"analyzer": {
"whitespace_analyzer": {
"type": "custom",
"tokenizer": "whitespace",
"filter": [
"lowercase",
"asciifolding"
]
}
}
}
},
"mappings": {
"mydocument": {
"properties": {
"autocomplete": {
"type": "text",
"fields": {
"raw": {
"type": "keyword"
},
"completion": {
"type": "text",
"analyzer": "whitespace_analyzer",
"search_analyzer": "standard"
}
}
},
"title": {
"type": "text"
},
"content": {
"type": "text"
}
}
}
}
}
内容:
POST test_content/mydocument
{ "title": "CubeSats to Space", "content": "With the VCLS effort, NASA has successfully advanced the commercial launch service choices for smaller payloads, providing viable dedicated small launch options as an alternative to the rideshare approach, said Jim Norman, director of Launch Services at NASA Headquarters in Washington. This first mission is opening the door for future launch options.", "autocomplete": "CubeSats to Space With the VCLS effort, NASA has successfully advanced the commercial launch service choices for smaller payloads, providing viable dedicated small launch options as an alternative to the rideshare approach, said Jim Norman, director of Launch Services at NASA Headquarters in Washington. This first mission is opening the door for future launch options." }
POST test_content/mydocument
{ "title": "Passing of Rona Ramon", "content": "NASA is deeply saddened by the passing of Rona Ramon, and we send our heartfelt condolences to her family and the people of Israel. Rona’s courage and inspiration in the face of tragedy have helped inspire a new generation to build on the legacy of her husband, space shuttle astronaut Ilan Ramon.", "autocomplete": "Passing of Rona Ramon NASA is deeply saddened by the passing of Rona Ramon, and we send our heartfelt condolences to her family and the people of Israel. Rona’s courage and inspiration in the face of tragedy have helped inspire a new generation to build on the legacy of her husband, space shuttle astronaut Ilan Ramon."}
POST test_content/mydocument
{ "title": "New Moon to Mars Exploration Approach in 2018", "content": "This year, we landed on Mars for the seventh time, and America remains the only country to have landed on Mars successfully. We created new U.S. commercial partnerships to land back on the Moon. We made breakthroughs in our quest to send humans farther into space than ever before. And, we contributed to remarkable advancements in aviation. I want to thank the entire NASA team for a fantastic year of American leadership in space, and I am confident we will build on our 2018 successes in 2019.", "autocomplete": "New Moon to Mars Exploration Approach in 2018 This year, we landed on Mars for the seventh time, and America remains the only country to have landed on Mars successfully. We created new U.S. commercial partnerships to land back on the Moon. We made breakthroughs in our quest to send humans farther into space than ever before. And, we contributed to remarkable advancements in aviation. I want to thank the entire NASA team for a fantastic year of American leadership in space, and I am confident we will build on our 2018 successes in 2019." }
我最终使用聚合来解决这个问题:
PUT test_content
{
"mappings": {
"mydocument": {
"properties": {
"autocomplete": {
"type": "keyword"
}
,
"title": {
"type": "text",
"analyzer": "standard"
},
"content": {
"type": "text"
}
}
}
}
}
POST test_content/mydocument
{ "title": "Passing of Rona Ramon", "content": "NASA is deeply saddened by the passing of Rona Ramon, and we send our heartfelt condolences to her family and the people of Israel. Rona’s courage and inspiration in the face of tragedy have helped inspire a new generation to build on the legacy of her husband, space shuttle astronaut Ilan Ramon.", "autocomplete": ["Passing","of","Rona","Ramon","NASA","is","deeply","saddened","by","the","passing","of","Rona","Ramon,","and","we","send","our","heartfelt","condolences","to","her","family","and","the","people","of","Israel.","Rona’s","courage","and","inspiration","in","the","face","of","tragedy","have","helped","inspire","a","new","generation","to","build","on","the","legacy","of","her","husband,","space","shuttle","astronaut","Ilan","Ramon."]}
POST test_content/mydocument
{ "title": "New Moon to Mars Exploration Approach in 2018", "content": "This year, we landed on Mars for the seventh time, and America remains the only country to have landed on Mars successfully. We created new U.S. commercial partnerships to land back on the Moon. We made breakthroughs in our quest to send humans farther into space than ever before. And, we contributed to remarkable advancements in aviation. I want to thank the entire NASA team for a fantastic year of American leadership in space, and I am confident we will build on our 2018 successes in 2019.", "autocomplete": [ "New","Moon","to","Mars","Exploration","Approach","in","2018","This","year,","we","landed","on","Mars","for","the","seventh","time,","and","America","remains","the","only","country","to","have","landed","on","Mars","successfully.","We","created","new","U.S.","commercial","partnerships","to","land","back","on","the","Moon.","We","made","breakthroughs","in","our","quest","to","send","humans","farther","into","space","than","ever","before.","And,","we","contributed","to","remarkable","advancements","in","aviation.","I","want","to","thank","the","entire","NASA","team","for","a","fantastic","year","of","American","leadership","in","space,","and","I","am","confident","we","will","build","on","our","2018","successes","in","2019." ] }
GET test_content/_search?pretty
{
"size": 0,
"aggregations": {
"autocomplete": {
"filter": {
"prefix": {
"autocomplete": "hum"
}
},
"aggregations": {
"autocomplete": {
"terms": {
"field": "autocomplete",
"include": "hum.*"
}
}
}
}
}
}
我们希望弹性搜索建议在索引中找到的词。我们正在使用版本:5.6.4.
如果我键入 "head",它应该建议 "headquarters",这是在索引中找到的一个词。最好它应该按出现次数对建议进行排序。
我试过几个教程,但它们都是 return 整个内容项而不是单词本身。我使用文档得出的最接近结果如下:
GET test_content/_search?pretty
{
"suggest": {
"text": "head",
"my-suggestion": {
"term": {
"field":"autocomplete"
}
}
}
}
但它没有给出任何结果,直到我输入:"headquarte"。
当我键入 "lead" 时,我期望 "leadership",但得到的结果是:"land"。错别字纠正可能很好,但不是我目前想要的。我首先想要获得一个稳定的工作单词建议功能,稍后可能包括拼写错误更正。
我也试过 edgeNGram
过滤器,但没有得到任何正确的结果。 whitespace
过滤器现在应该没问题。前缀搜索对我来说没问题。
配置:
PUT test_content
{
"settings": {
"analysis": {
"analyzer": {
"whitespace_analyzer": {
"type": "custom",
"tokenizer": "whitespace",
"filter": [
"lowercase",
"asciifolding"
]
}
}
}
},
"mappings": {
"mydocument": {
"properties": {
"autocomplete": {
"type": "text",
"fields": {
"raw": {
"type": "keyword"
},
"completion": {
"type": "text",
"analyzer": "whitespace_analyzer",
"search_analyzer": "standard"
}
}
},
"title": {
"type": "text"
},
"content": {
"type": "text"
}
}
}
}
}
内容:
POST test_content/mydocument
{ "title": "CubeSats to Space", "content": "With the VCLS effort, NASA has successfully advanced the commercial launch service choices for smaller payloads, providing viable dedicated small launch options as an alternative to the rideshare approach, said Jim Norman, director of Launch Services at NASA Headquarters in Washington. This first mission is opening the door for future launch options.", "autocomplete": "CubeSats to Space With the VCLS effort, NASA has successfully advanced the commercial launch service choices for smaller payloads, providing viable dedicated small launch options as an alternative to the rideshare approach, said Jim Norman, director of Launch Services at NASA Headquarters in Washington. This first mission is opening the door for future launch options." }
POST test_content/mydocument
{ "title": "Passing of Rona Ramon", "content": "NASA is deeply saddened by the passing of Rona Ramon, and we send our heartfelt condolences to her family and the people of Israel. Rona’s courage and inspiration in the face of tragedy have helped inspire a new generation to build on the legacy of her husband, space shuttle astronaut Ilan Ramon.", "autocomplete": "Passing of Rona Ramon NASA is deeply saddened by the passing of Rona Ramon, and we send our heartfelt condolences to her family and the people of Israel. Rona’s courage and inspiration in the face of tragedy have helped inspire a new generation to build on the legacy of her husband, space shuttle astronaut Ilan Ramon."}
POST test_content/mydocument
{ "title": "New Moon to Mars Exploration Approach in 2018", "content": "This year, we landed on Mars for the seventh time, and America remains the only country to have landed on Mars successfully. We created new U.S. commercial partnerships to land back on the Moon. We made breakthroughs in our quest to send humans farther into space than ever before. And, we contributed to remarkable advancements in aviation. I want to thank the entire NASA team for a fantastic year of American leadership in space, and I am confident we will build on our 2018 successes in 2019.", "autocomplete": "New Moon to Mars Exploration Approach in 2018 This year, we landed on Mars for the seventh time, and America remains the only country to have landed on Mars successfully. We created new U.S. commercial partnerships to land back on the Moon. We made breakthroughs in our quest to send humans farther into space than ever before. And, we contributed to remarkable advancements in aviation. I want to thank the entire NASA team for a fantastic year of American leadership in space, and I am confident we will build on our 2018 successes in 2019." }
我最终使用聚合来解决这个问题:
PUT test_content
{
"mappings": {
"mydocument": {
"properties": {
"autocomplete": {
"type": "keyword"
}
,
"title": {
"type": "text",
"analyzer": "standard"
},
"content": {
"type": "text"
}
}
}
}
}
POST test_content/mydocument
{ "title": "Passing of Rona Ramon", "content": "NASA is deeply saddened by the passing of Rona Ramon, and we send our heartfelt condolences to her family and the people of Israel. Rona’s courage and inspiration in the face of tragedy have helped inspire a new generation to build on the legacy of her husband, space shuttle astronaut Ilan Ramon.", "autocomplete": ["Passing","of","Rona","Ramon","NASA","is","deeply","saddened","by","the","passing","of","Rona","Ramon,","and","we","send","our","heartfelt","condolences","to","her","family","and","the","people","of","Israel.","Rona’s","courage","and","inspiration","in","the","face","of","tragedy","have","helped","inspire","a","new","generation","to","build","on","the","legacy","of","her","husband,","space","shuttle","astronaut","Ilan","Ramon."]}
POST test_content/mydocument
{ "title": "New Moon to Mars Exploration Approach in 2018", "content": "This year, we landed on Mars for the seventh time, and America remains the only country to have landed on Mars successfully. We created new U.S. commercial partnerships to land back on the Moon. We made breakthroughs in our quest to send humans farther into space than ever before. And, we contributed to remarkable advancements in aviation. I want to thank the entire NASA team for a fantastic year of American leadership in space, and I am confident we will build on our 2018 successes in 2019.", "autocomplete": [ "New","Moon","to","Mars","Exploration","Approach","in","2018","This","year,","we","landed","on","Mars","for","the","seventh","time,","and","America","remains","the","only","country","to","have","landed","on","Mars","successfully.","We","created","new","U.S.","commercial","partnerships","to","land","back","on","the","Moon.","We","made","breakthroughs","in","our","quest","to","send","humans","farther","into","space","than","ever","before.","And,","we","contributed","to","remarkable","advancements","in","aviation.","I","want","to","thank","the","entire","NASA","team","for","a","fantastic","year","of","American","leadership","in","space,","and","I","am","confident","we","will","build","on","our","2018","successes","in","2019." ] }
GET test_content/_search?pretty
{
"size": 0,
"aggregations": {
"autocomplete": {
"filter": {
"prefix": {
"autocomplete": "hum"
}
},
"aggregations": {
"autocomplete": {
"terms": {
"field": "autocomplete",
"include": "hum.*"
}
}
}
}
}
}