I think I have a very specific problem here and I was just looking for some data constellations/queries to might help =) Btw. still using ES 5.6.4 here =/
I decided to use nested document because we have multiple variations of entries but tagged with "owners" to decide who can see which documents:
DELETE test
PUT /test
{
"mappings": {
"entry" : {
"properties" : {
"variations" : {
"type" : "nested"
}
}
}
}
}
POST test/entry
{
"variations": [
{
"owner": "group",
"data": {
"firstName": "John",
"lastName": "Doe"
}
},
{
"owner": "user1",
"data": {
"lastName": "Shepard"
}
}
]
}
GET test/_search
{
"query": {
"nested": {
"path": "variations",
"query": {
"bool": {
"must": [
{
"bool": {
"should": [
{
"terms": {
"variations.owner": [
"group",
"user1"
]
}
}
]
}
}
]
}
}
}
}
}
The problem is now, if I do a must search on multiple fields, of course elastic search treats the variations as separated documents and won't return the document if the following search is executed (I removed the owner-bool for readability):
GET test/_search
{
"query": {
"nested": {
"path": "variations",
"query": {
"bool": {
"must": [
{
"match": {
"variations.data.firstname": "John"
}
},
{
"match": {
"variations.data.lastName": "Shepard"
}
}
]
}
}
}
}
}
But now, after reading the documentation of nested mapping again, I am totally unsure if this is even in any case the right thing to use when I need to have an owner per "variation"?