我在弹性搜索查询中苦苦挣扎。
这些是示例文档,我将对其进行查询。这些是具有通用属性的文档
[
{
"field1": "value",
"properties": [
{
"propertyBooleanValue": null,
"propertyName": "Product name",
"propertyDateValue": null,
"propertyType": "TEXT",
"propertyStringValue": "SUPER Cool Extreme",
"propertyNumericValue": null
},
{
"propertyBooleanValue": null,
"propertyName": "Product expiration date",
"propertyDateValue": null,
"propertyType": "DATE",
"languageCode": null,
"propertyNumericValue": null
}
]
},
{
"field1": "blah blah",
"properties": [
{
"propertyBooleanValue": null,
"propertyName": "Product name",
"propertyDateValue": null,
"propertyType": "TEXT",
"propertyStringValue": "So boring",
"propertyNumericValue": null
},
{
"propertyBooleanValue": null,
"propertyName": "Product expiration date",
"propertyDateValue": "2020-04-02",
"propertyType": "DATE",
"languageCode": null,
"propertyNumericValue": null
}
]
},
{
"field1": "wow2",
"properties": [
{
"propertyBooleanValue": null,
"propertyName": "Product name",
"propertyDateValue": null,
"propertyType": "TEXT",
"propertyStringValue": "iPear",
"propertyNumericValue": null
},
{
"propertyBooleanValue": null,
"propertyName": "Product expiration date",
"propertyDateValue": null,
"propertyType": "DATE",
"languageCode": null,
"propertyNumericValue": null
}
]
}
]
我只想查询具有嵌套对象的文档,该对象具有“propertyName”=“产品到期日期”和“propertyDateValue”= null 的属性
我使用查询,但它返回所有文档:
{
"query": {
"bool": {
"must": [
{
"nested": {
"query": {
"bool": {
"must": [
{
"bool": {
"must_not": [
{
"exists": {
"field": "properties.propertyDateValue"
}
}
]
}
},
{
"term": {
"properties.propertyName": {
"value": "Product expiration date"
}
}
}
]
}
},
"path": "properties"
}
}
]
}
}
}
我们使用弹性搜索 7.7