Ответ 1
Вы пробовали завершить предложение? Один из способов решения вашей проблемы заключается в следующем:
1) Создайте индекс:
curl -XPUT "http://localhost:9200/test_index/"
2) Создайте сопоставление, используя тип тестировщика завершения:
curl -XPUT "http://localhost:9200/test_index/product/_mapping" -d'
{
"product": {
"properties": {
"category": {
"type": "string"
},
"cost": {
"type": "string"
},
"createDate": {
"type": "date",
"format": "dateOptionalTime"
},
"description": {
"type": "string"
},
"rating": {
"type": "string"
},
"sales": {
"type": "string"
},
"tags": {
"type": "string"
},
"title": {
"type": "string"
},
"suggest": {
"type": "completion",
"index_analyzer": "simple",
"search_analyzer": "simple",
"payloads": false
}
}
}
}'
3) Добавьте свои документы:
curl -XPUT "http://localhost:9200/test_index/product/1" -d'
{
"title": "Product1",
"sales": "6",
"rating": "0.0",
"cost": "45.00",
"tags": [
"blog",
"magazine",
"responsive",
"two columns",
"wordpress"
],
"suggest": {
"input": [
"blog",
"magazine",
"responsive",
"two columns",
"wordpress"
]
},
"category": "wordpress",
"description": "Product1 Description",
"createDate": "2013-12-19"
}'
curl -XPUT "http://localhost:9200/test_index/product/2" -d'
{
"title": "Product2",
"sales": "6",
"rating": "0.0",
"cost": "45.00",
"tags": [
"blog",
"paypal",
"responsive",
"skrill",
"wordland"
],
"suggest": {
"input": [
"blog",
"paypal",
"responsive",
"skrill",
"wordland"
]
},
"category": "wordpress",
"description": "Product1 Description",
"createDate": "2013-12-19"
}'
4) И затем запрос с использованием конечной точки _suggest:
curl -XPOST "http://localhost:9200/test_index/_suggest" -d'
{
"product_suggest":{
"text":"word",
"completion": {
"field" : "suggest"
}
}
}'
и вы вернете результаты, которые вы ожидали:
{
"_shards": {
"total": 2,
"successful": 2,
"failed": 0
},
"product_suggest": [
{
"text": "word",
"offset": 0,
"length": 4,
"options": [
{
"text": "wordland",
"score": 1
},
{
"text": "wordpress",
"score": 1
}
]
}
]
}
Это решение можно было бы немного уточнить, в частности, путем обрезки некоторых повторяющихся данных, но это должно указывать на правильное направление.