Anonymous
Как выполнить фасетный поиск по нескольким вложенным полям в клиенте Elasticsearch Java API?
Сообщение
Anonymous » 19 ноя 2024, 14:05
Это мои примеры документов.
Код: Выделить всё
"id" : "1",
"title" : "test",
"description" : "test",
"price" : 100.0,
"category_id" : "1",
"characteristics" : [
{
"characteristic_id" : "1",
"text_value" : "red"
},
{
"characteristic_id" : "2",
"numeric_value" : 15
},
{
"characteristic_id" : "3",
"numeric_value" : 20
}
]
"id" : "2",
"title" : "test",
"description" : "test",
"price" : 200.0,
"category_id" : "1",
"characteristics" : [
{
"characteristic_id" : "1",
"text_value" : "blue"
},
{
"characteristic_id" : "2",
"numeric_value" : 10
},
{
"characteristic_id" : "3",
"numeric_value" : 5
}
]
И запрос к моему индексу должен быть таким. Как я могу написать это, используя новый клиент Java Api для Elasticsearch?
Код: Выделить всё
GET product/_search
{
"query": {
"bool": {
"must": [
{
"nested": {
"path": "characteristics",
"query": {
"bool": {
"must": [
{
"term": {
"characteristics.characteristic_id": 1
}
},
{
"term": {
"characteristics.text_value": "blue"
}
}
]
}
}
}
},
{
"nested": {
"path": "characteristics",
"query": {
"bool": {
"must": [
{
"term": {
"characteristics.characteristic_id": 3
}
},
{
"range": {
"characteristics.numeric_value": {
"gte": 1,
"lte": 7
}
}
}
]
}
}
}
},
{
"term": {
"category_id": 1
}
},
{
"range": {
"price": {
"gt": 10.0,
"lt": 500.0
}
}
}
],
"should": [
{
"match": {
"title": "te"
}
}
]
}
}
}
В официальной документации очень мало информации. Стоит ли вообще использовать этот API, если к нему нет нормальной документации, и писать все запросы вручную?
Подробнее здесь:
https://stackoverflow.com/questions/791 ... va-api-cli
1732014332
Anonymous
Это мои примеры документов. [code]"id" : "1", "title" : "test", "description" : "test", "price" : 100.0, "category_id" : "1", "characteristics" : [ { "characteristic_id" : "1", "text_value" : "red" }, { "characteristic_id" : "2", "numeric_value" : 15 }, { "characteristic_id" : "3", "numeric_value" : 20 } ] "id" : "2", "title" : "test", "description" : "test", "price" : 200.0, "category_id" : "1", "characteristics" : [ { "characteristic_id" : "1", "text_value" : "blue" }, { "characteristic_id" : "2", "numeric_value" : 10 }, { "characteristic_id" : "3", "numeric_value" : 5 } ] [/code] И запрос к моему индексу должен быть таким. Как я могу написать это, используя новый клиент Java Api для Elasticsearch? [code]GET product/_search { "query": { "bool": { "must": [ { "nested": { "path": "characteristics", "query": { "bool": { "must": [ { "term": { "characteristics.characteristic_id": 1 } }, { "term": { "characteristics.text_value": "blue" } } ] } } } }, { "nested": { "path": "characteristics", "query": { "bool": { "must": [ { "term": { "characteristics.characteristic_id": 3 } }, { "range": { "characteristics.numeric_value": { "gte": 1, "lte": 7 } } } ] } } } }, { "term": { "category_id": 1 } }, { "range": { "price": { "gt": 10.0, "lt": 500.0 } } } ], "should": [ { "match": { "title": "te" } } ] } } } [/code] В официальной документации очень мало информации. Стоит ли вообще использовать этот API, если к нему нет нормальной документации, и писать все запросы вручную? Подробнее здесь: [url]https://stackoverflow.com/questions/79196103/how-to-make-facet-search-by-multiple-nested-fields-in-elasticsearch-java-api-cli[/url]