字段中的大写字母导致elasticsearch中的查询失败

gdx19jrr  于 2021-06-10  发布在  ElasticSearch
关注(0)|答案(1)|浏览(384)

我有一个查询,搜索包含一些值的成绩单。它应该匹配属于特定租户的每个文档。当查询的术语筛选器没有大写字母时,查询工作,但如果没有大写字母,则查询失败。
我应该把我的租户id编码成只使用小写字母的格式吗?或者有没有一种方法可以使术语filter(或者类似的filter)区分大小写?或者我需要在 tenant_id 字段以保留其大小写?

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

xqnpmsa81#

尝试 match 而不是 term :

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

或者,你可以 term 但是使用 keyword 子字段(如果Map中存在这样的字段)

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

相关问题