#elasticsearch
Вопрос:
Допустим, у меня есть индекс elasticsearch, определенный следующим образом:
doc_id : {type : keyword} content : {type : text}
И документ:
{ 'doc_id' : '12A5F', 'content' : 'California is a state in the Western United States. It is bordered by Nevada to the east, Arizona to the southeast, the Pacific Ocean to the west, Oregon to the north, and the Mexican state of Baja California to the south. [13] Sacramento is the state's capital, while Los Angeles is the most populous city in the state and the second most populous city in the country (after New York City).' }
Если бы я сделал следующий запрос:
{ "query": { "match" : { "content" : "Sacramento" } }, "highlight" : { fields" : { "content" : {} } } }
Это дало бы мне следующий ответ:
{ 'doc_id' : '12A5F', 'content' : 'California is a state in the Western United States. It is bordered by Nevada to the east, Arizona to the southeast, the Pacific Ocean to the west, Oregon to the north, and the Mexican state of Baja California to the south. [13] Sacramento is the state's capital, while Los Angeles is the most populous city in the state and the second most populous city in the country (after New York City).', "highlight" : { "content" : [ "lt;emgt;Sacramentolt;/emgt; is the state's capital, while Los Angeles is the most populous city in the state and the second most populous city in the country (after New York City)." ] } }
Мне нужен полный текст с выделенным поисковым термином:
'content' : 'California is a state in the Western United States. It is bordered by Nevada to the east, Arizona to the southeast, the Pacific Ocean to the west, Oregon to the north, and the Mexican state of Baja California to the south. [13] lt;emgt;Sacramentolt;/emgt; is the state's capital, while Los Angeles is the most populous city in the state and the second most populous city in the country (after New York City).',
Есть ли какой-нибудь способ сделать это с помощью ElasticSearch?