I was wondering whether it was possible in elasticsearch to write a
query that says something like, "return all documents in which the
contents of field 'foo.*.bar' matches a certain keyword." I know
elasticsearch can perform wildcard matches on the content, but for the
data I'm working with I'll need to specify the field names themselves
using wildcards.
My mappings are as follows:
curl -XPOST 'http://localhost:9200/userprofiles' -d '{
"mappings": {
"user": {
"properties: {
"events": {
"type": "object", "dynamic": "true"
}
},
"dynamic_templates": [
{
"type": {
"path_match": "*.*.type", "mapping": { "type": "string" }
}
"dat": {
"path_match": "*.*.dat", "mapping": { "type": "string" }
}
}
]
}
}
}'
Let's say I insert these two documents:
curl -XPUT 'http://localhost:9200/userprofiles/user/1' -d '{
"events": {
"10": [
{ type: "view", dat: "http://www.google.com" }
],
"30": [
{ type: "view", dat: "http://www.yahoo.com" },
{ type: "share", dat: "http://www.facebook.com" }
]
}
}'
curl -XPUT 'http://localhost:9200/userprofiles/user/2' -d '{
"events": {
"15": [
{ type: "view", dat: "http://www.cnet.com" }
]
}
}
The numbers "10", "30", and "15" can be any arbitrary numbers.
I want to write a query that says, "fetch all documents that have at
least one 'events.*.type' that equals 'share'" (and would hence fetch
only document 1). Essentially, something like this:
curl -XPOST 'http://localhost:9200/userprofiles/_search?pretty=true' -
d '{
"filter": {
"term": { "user-events.*.type": "share" }
}
}'
...but elasticsearch doesn't seem to like the * here. Is there any
alternate way to achieve this? Unfortunately I do not have any
control over the structure of the documents.