Hi! I have been trying to implement my application with tagging feature. Tags would consist of name field and value field and be nested objects under value tags.
Code: (taken from response of match_all search)
{ "_source" : { "examinfo": "lots of infos", "tags" : [ { "name" : "subject", "value" : "maths" }, { "name" : "professor", "value" : "Math Master" }, { "name" : "year", "value" : "2016" }, { "name" : "term", "value" : "second" }, { "name" : "grade", "value" : "second" } ], "data" : "exam data - images" } },
So, what I am trying to do is to be able to filter my query with multiple tags and because as you have probably noticed in this example, and yes this will happen , two different tag-types have the same value. So natural instinct would be to filter them with both 'name'(type) field and value field. (Hope this is the right approach?)
{ "size": 10, "query": { "nested": { "path": "tags", "query": { "bool": { "must": [ { "match": { "tags.year": "2015"}}, { "match": { "tags.term": "second"}}, ] } } } } }
I tried this because I have found an example on stack, which "works" like this. Link: Stack Example
I think this example is very similar to mine as it uses features as I use tags. Sadly, when I tried to implement it in my case, it didn't work. Is there any obvious solution, which I am missing?
So, what I want to do is; I want to be able to search through my database with declaring tags that test must match (user would have selected them). One other question, is it possible to aggregate whole object? In this example, it would be whole tag object?
Also my mappings of data:
{ "template": "*", "order": 0, "settings": { "number_of_shards": 3, "number_of_replicas": 0 }, "mappings": { "exams": { "_timestamp": { "enabled": true }, "properties": { "description": { "type": "string"}, "provider": { "type": "object", "properties": { "name": { "type": "string"}, "uid": { "type": "integer"} } }, "tags": { "type": "nested", "properties": { "name": { "type": "string", "analyzer": "whitespace" }, "value": { "type": "string", "analyzer": "whitespace" } } }, "data": { "type": "nested", "properties": { "preview": { "type": "boolean"}, "order": { "type": "integer"}, "image": { "type": "string"} } } } } } }