Using query_string to search on wildcard field name and specific value
I'm using NEST to index a doc, which in .net looks like:
public class Supplier
{
public string AccountId {get; set}
public int Level {get; set}
public Dictionary<string, object> Dimensions {get; set;}
}
When it's in the index, it looks something like this:
{
"accountId": "1d36a070-4699-e611-80r9-005056953547",
"dimensions": {
"name": "Some Special Account Name",
"level": 2
"workCategory[0].name": "Name 1",
"workCategory[0].refId": "d9b5ec75-5697-e611-8113-005056956082",
"workCategory[1].name": "Name 2",
"workCategory[1].refId": "51b2e075-5692-e611-8113-005055956082",
}
}
This is a simplistic version of our doc, but for the purposes of the demo, we have to store each workCategory
as a flat list like this.
What I'm trying to do is find docs where any 'workCategory refId' is equal to d9b5ec75-5697-e611-8113-005056956082
So I've tried query_string
like this:
{
"query": {
"query_string": {
"query": "workCategory[./*].refId:\"d9b5ec75-5697-e611-8113-005056956082\""
}
}
}
When I run this, I get hits for all docs - including docs that don't have d9b5ec75-5697-e611-8113-005056956082
in any workCategory[*].refId
I'm not doing anything with the mapping, other than using Automap.
The mapping currently looks like the below
Could it be that the dimensions are not nested? Not sure where I'm going wrong at the moment
{
"my_index_name": {
"mappings": {
"properties": {
"accountId": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"dimensions": {
"properties": {
"name": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"level": {
"type": "long"
},
"workCategory[0]": {
"properties": {
"name": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"refId": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
},
"workCategory[1]": {
"properties": {
"name": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"refId": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
}
}
}
}
}
}
}