QueryContainerDescriptor Elasticsearch - 获取所有描述不等于 String.Empty 的文档
QueryContainerDescriptor Elasticsearch - Get all document with description is not equal to String.Empty
我正在使用 QueryContainerDescriptor 来填充过滤器。
我想获取所有描述不等于 String.Empty.
的文档
我试过:
public static QueryContainerDescriptor<T> FilterSummaryEmpty<T>(this QueryContainerDescriptor<T> qd)
where T : ElasticEntityDoc
{
qd.Bool(b=>
b.MustNot(mn =>
mn.Term(f => f.Description, string.Empty)
));
return qd;
}
但它不起作用。
我也尝试过使用正则表达式,但没有成功。
我做错了什么?
如果您使用standard analyser
,检查空将不起作用,因为它不会被分析,因为它是空的。所以在索引中不会有任何东西 empty
来匹配。
要检查这一点,您需要在映射中将另一个字段中的字段复制为 not_analyzed
。 Reference
因此,您可以在复制的字段上检查为空,并在 description
字段上检查其他查询。
还有一种检查方法。您可以使用 exists
While a field is deemed non-existent if the JSON value is null or [], these values will indicate the field does exist:
Empty strings, such as "" or "-" Arrays containing null and another
value, such as [null, "foo"] A custom null-value, defined in field
mapping
我正在使用 QueryContainerDescriptor 来填充过滤器。 我想获取所有描述不等于 String.Empty.
的文档我试过:
public static QueryContainerDescriptor<T> FilterSummaryEmpty<T>(this QueryContainerDescriptor<T> qd)
where T : ElasticEntityDoc
{
qd.Bool(b=>
b.MustNot(mn =>
mn.Term(f => f.Description, string.Empty)
));
return qd;
}
但它不起作用。
我也尝试过使用正则表达式,但没有成功。 我做错了什么?
如果您使用standard analyser
,检查空将不起作用,因为它不会被分析,因为它是空的。所以在索引中不会有任何东西 empty
来匹配。
要检查这一点,您需要在映射中将另一个字段中的字段复制为 not_analyzed
。 Reference
因此,您可以在复制的字段上检查为空,并在 description
字段上检查其他查询。
还有一种检查方法。您可以使用 exists
While a field is deemed non-existent if the JSON value is null or [], these values will indicate the field does exist:
Empty strings, such as "" or "-" Arrays containing null and another value, such as [null, "foo"] A custom null-value, defined in field mapping