I'm trying to solve the following high level requirement:
- save arbitrary number of key value pairs on a document which already has properties: name and description
- values can be numbers which should be 'range searchable'
- values can include geo_points which need to be 'geo searchable'
I've created the following index.
{
"settings": {
"index" : {
"number_of_shards" : 3,
"number_of_replicas" : 1
}
},
"mappings": {
"_doc": {
"dynamic": "strict",
"properties": {
"name": {
"type": "text",
"analyzer": "german",
},
"description": {
"type": "text",
"analyzer": "german"
},
"attributes": {
"type": "nested",
"properties": {
"key": { "type": "text" },
"val_bool": { "type": "boolean" },
"val_int": { "type": "integer" },
"val_float": { "type": "float" },
"val_string": { "type": "text" },
"val_geo": { "type": "geo_point" },
"val_date": { "type": "date" }
}
}
}
}
}
}
We use nested objects to be able to save a list of key-value-pairs for each document. Each key-value-pair uses one typed val_* property to persist the typed value. Thus enabling special searches for special types, Range-Query for example.
To search in documents we use query_string query to allow users to be very specific in searches. For example. Search documents where name:foo AND description:bar. (that works as expected)
The same scenario should be possible with key-value-pairs.So for example: attributes.key:someKey AND attributes.val_string:someStringValue. This scenario requires a nested query which we use and works as expected.
What isnt't working: If we search for name:foo AND attributes.key:someKey we get no results.
It's seems that 'nested query_string queries' AND 'just query_string queries' arent't supported in combination. Is that true? What's a feasible workaround to implement the described requirement?
The query looks like this:
{
"query": {
"bool": {
"should": [
{
"query_string": {
"query": "attributes.key:someKey AND name:foo",
"default_operator": "and",
"fields": [
"name",
"description"
]
}
},
{
"nested": {
"query": {
"query_string": {
"query": "attributes.key:someKey AND name:foo",
"default_operator": "and",
"fields": [
"attributes.key",
"attributes.val_string"
]
}
},
"path": "attributes"
}
}
]
}
}
}
Any help is greatly appreciated. Thank you in advance.