Complex nested query with wildcards


(Sergei Petrov) #1

Hello, I stack with one problem. I have an element which contains array of nested objects. For example I create a new index.
GET /test/test/_mapping
{
"test": {
"mappings": {
"test": {
"properties": {
"columnName": {
"type": "text"
},
"list": {
"type": "nested",
"properties": {
"black cat": {
"type": "long"
},
"red fox": {
"type": "long"
},
"white cat": {
"type": "long"
},
"white dog": {
"type": "long"
}
}
},
"name": {
"type": "text"
}
}
}
}
}
}

This "list" can be modified at any time, so the customer can add a new objects. ("brown dog", etc.)
For example one of the objects can looks like:
{
"_index": "test",
"_type": "test",
"_id": "1",
"_score": 1,
"_source": {
"name": "First example",
"columnName": "Something",
"list": [
{
"white cat": 1
}
]
}
}

I need to create query which can sum all numbers in fields which are suitable for the regexp. For example, "*dog".
If we have the following element:
{
"_index": "test",
"_type": "test",
"_id": "3",
"_score": 1,
"_source": {
"name": "Third example",
"columnName": "Something",
"list": [
{
"white dog": 3,
"black dog": 2,
"white cat": 1
}
]
}
}
From the query with "list.*dog" wildcard I must get 5 (3 + 2).

I read about Multi_Match query which supports wildcard in name of fields, but in this situation I need to know the value. And I also saw a Range query in which I can say that field must be greater than 0, but Range query doesn't support wildcard. But how to combine these queries and count the sum of the fields, I don't know.


(system) #2

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.