Pobably this question was answered somewhere but i cannot find it . so I am asking for help I have a nested list of properties for my product model. something like this
[
{
ID: "Product1",
...
Properties: [
{ "Source": "Color", Value: "green"},
{ "Source": "Size", Value: "2"},
]
},
{
ID: "Product2",
...
Properties: [
{ "Source": "Color", Value: "blue"},
{ "Source": "Size", Value: "2"},
]
},
{
ID: "Product3",
....
Properties: [
{ "Source": "Color", Value: "red"},
{ "Source": "Size", Value: "1"},
]
},
]
Index mapping:
"properties" : {
"type" : "nested",
"properties" : {
"source" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"value" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
}
}
},
And I need my search query to find only the products that have color green or blue and size 2.
i created this query for my Search request but it will return an empty result.
new Nest.NestedQuery
{
Path = new Nest.Field("properties"),
Query = new Nest.BoolQuery() {
Must = new Nest.QueryContainer[] {
new Nest.BoolQuery()
{
Must = new Nest.QueryContainer[] {
new Nest.TermQuery()
{
Field = new Nest.Field("properties.source.keyword"),
Value = "Color"
},
new Nest.TermsQuery()
{
Field = new Nest.Field("properties.value.keyword"),
Terms = new[] { "green", "blue"}
}
}
}
},
new Nest.BoolQuery()
{
Must = new Nest.QueryContainer[] {
new Nest.TermQuery()
{
Field = new Nest.Field("properties.source.keyword"),
Value = "Size"
},
new Nest.TermsQuery()
{
Field = new Nest.Field("properties.value.keyword"),
Terms = new[] { "2"}
}
}
}
}
}
}
Can you please help me what did I used wrong by building this kind of query? thank you