Упругое Поисковое слово - PullRequest
       44

Упругое Поисковое слово

0 голосов
/ 22 января 2019

Мы хотим, чтобы упругий поиск подсказывал слова, найденные в индексе.Мы используем версию: 5.6.4.

Если я наберу слово «голова», оно должно предложить «штаб-квартира», слово, найденное в индексе.Желательно сортировать предложения по появлению.

Я пробовал несколько учебных пособий, но все они возвращают весь элемент контента вместо самого слова.Наиболее близким, с чем я столкнулся при использовании документации, является следующее:

GET test_content/_search?pretty
{
  "suggest": { 
      "text": "head", 
      "my-suggestion": { 
         "term": { 
            "field":"autocomplete"
         }
      }
   }
}

Но это не дает результатов, пока я не наберу: "штаб-квартира".

Когда я набираю «лидерство», я ожидаю «лидерство», но в результате получаю «земля».Исправление опечаток может быть хорошим, но не то, что я ищу в данный момент.Сначала я хочу получить стабильную функциональность подсказки рабочего слова и позже включить исправление опечаток.

Я также пытался поиграться с фильтром 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." }

1 Ответ

0 голосов
/ 25 января 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.*"
               }
            }
         }
      }
    }
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...