字段中的大写字母导致查询在弹性搜索中失败



我有一个查询,它搜索包含一些值的转录本。它应该匹配属于特定租户的每个文档。查询在术语过滤器没有大写字母时有效,但在有大写字母时失败。

我应该将租户ID编码为只使用小写字母的格式吗?或者有没有一种方法可以使"过滤器"(或类似的过滤器(区分大小写?还是我需要在tenant_id字段上启用一些选项来保留其大小写?

{
'query': {
'bool': {
'must': [{'match': {'transcript': 'hello, world!'}}],
'filter': [
{'term': {'tenant_id': 'XRqtv5O91WEEt'}}
]
}
}
}

尝试使用match而不是term:

{
'query': {
'bool': {
'must': [{'match': {'transcript': 'hello, world!'}}],
'filter': [
{'match': {'tenant_id': 'XRqtv5O91WEEt'}}
^^^^^
]
}
}
}

或者,您可以保留term,但使用keyword子字段(如果映射中存在这样的字段(

{
'query': {
'bool': {
'must': [{'match': {'transcript': 'hello, world!'}}],
'filter': [
{'term': {'tenant_id.keyword': 'XRqtv5O91WEEt'}}
^^^^^^^^
]
}
}
}

最新更新