I have a problem with creating a query to Elasticsearch with many conditions. My model looks like:
data class Product(
@Id
val id: String? = null,
val category: String,
val imagesUrls: List<String>,
@Field(type = FieldType.Double)
val price: Double?,
@Field(type = FieldType.Nested)
val parameters: List<Parameter>?
)
data class Parameter(
val key: String,
val values: List<String>
)
I would like to query products by:
- category (for example
cars) - price (between 20k $ and 50k $)
- and parameters -> For example products with many parameters, like key
capacityvalues4L,5Land second parameter gear transmission valuesmanual
My current query looks like this:
GET data/_search
{
"size": 10,
"query": {
"bool": {
"must": [
{
"term": {
"category.keyword": {
"value": "cars"
}
}
},
{
"nested": {
"path": "parameters",
"query": {
"bool": {
"must": [
{"term": {
"parameters.key.keyword": {
"value": "Capacity"
}
}},
{
"term": {
"parameters.key": {
"value": "4L, 5L"
}
}
}
]
}
}
}
}
]
}
}
- Could you tell me how to filter the product when parameter key is equal to Capacity and check that the values list contains one of the values?
- How to combine many this kind operations in one query?
Example data:
{
"category":"cars",
"name":"Ferrari",
"price":50000,
"parameters":[
{
"key":"capacity",
"values":"4L"
},
{
"key":"gear transmission",
"values":"automcatic"
}
]
}