I am trying to write a query that will find any document where the path campaigns.erp*.campaigns.campaignCode contains a value. I am stuck.
Do you guys have any idea how to achieve this?
If you run the code below then I would expect the query to return 2 documents since the first and last POST contains documents where the path campaigns.erp*.campaigns.campaignCode contains a value.
I tried using the query strings API, but I did not make much progress.
PUT /campaigns
{
"mappings": {
"properties": {
"campaigns": {
"type": "nested",
"properties": {
"erp1": {
"properties": {
"campaigns": {
"type": "nested",
"properties": {
"campaignCode": {
"type": "keyword"
}
}
}
}
},
"erp2": {
"properties": {
"campaigns": {
"type": "nested",
"properties": {
"campaignCode": {
"type": "keyword"
}
}
}
}
}
}
}
}
}
}
POST /campaigns/_doc
{
"campaigns": {
"erp1": {
"campaigns": [
{
"campaignCode": "1"
}
]
},
"erp2": {
"campaigns": [
{
"campaignCode": "2"
}
]
}
}
}
POST /campaigns/_doc
{
"campaigns": {
"erp1": {
"campaigns": []
},
"erp2": {
"campaigns": []
}
}
}
POST /campaigns/_doc
{
"campaigns": {
"erp1": {
"campaigns": []
},
"erp2": {
"campaigns": [
{
"campaignCode": "3"
}
]
}
}
}
GET /campaigns/_search
{
"query": {
"nested": {
"path": "campaigns",
"query": {
"query_string": {
"default_field": "campaigns.erp*.campaigns.campaignCode",
"query": "*"
}
}
}
}
}