【问题标题】:Capital letters in field causing query to fail in elasticsearch字段中的大写字母导致查询在弹性搜索中失败
【发布时间】:2021-02-15 07:01:58
【问题描述】:

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

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

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

【问题讨论】:

    标签: python elasticsearch elasticsearch-py


    【解决方案1】:

    尝试使用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'}}
                                        ^^^^^^^^
                ]
            }
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-09-24
      • 2016-10-04
      • 1970-01-01
      • 1970-01-01
      • 2018-11-03
      • 1970-01-01
      • 1970-01-01
      • 2016-08-10
      相关资源
      最近更新 更多