【问题标题】:Query Multi_Field with Elasticutils使用 Elasticutils 查询 Multi_Field
【发布时间】:2014-02-03 21:59:47
【问题描述】:

我在 Elastic Search 中为我的索引定义了以下映射,其中包含一种 multi_field 类型。

{
    'station': {
       "properties" :{
           'id': {'type': 'integer'},
           'call': {'type': 'multi_field', 
                    'fields' : {
                               'call': {'type': 'string', 'analyzer': 'whitespace'},
                               'raw': {'type': 'string', 'index': 'not_analyzed'}
                               }
                    }
        }
    }
}

我喜欢 Mozilla 的 ElasticUltis,但我找不到查询 multi_field 字段的方法。

我本来希望是这样的:

myQuery = S.query(call_raw__wildcard="value")

有人知道如何使用 elasticutils 查询 multi_field 字段吗?

【问题讨论】:

    标签: django elasticsearch elasticutils


    【解决方案1】:

    首先,您的multi_field 定义不正确。您应该有一个与rawautocomplete 处于同一级别的call 主字段。请参阅multi_field docs

    然后可以查询主字段为call,原始字段为call.raw

    【讨论】:

    • 感谢您指出我的 multi_field 定义中的错误。我已经相应地更新了定义。不幸的是,ElasticUtils 不允许myQuery=S.query(call.raw__wildcard="value")。所以我仍然想知道 ElasticUtils 是否有办法访问“call.raw”字段
    • 不知道 ElasticUtils - 我会考虑使用官方 Python 客户端 elasticsearch.org/guide/en/elasticsearch/client/python-api/… - 它公开了完整的 Elasticsearch API,因此您不必围绕客户端实现工作。
    【解决方案2】:

    好的 - 我在 multi_field 文档 (tnx @DrTech) 中找到了解决方法。如果添加了“path”:“just_name”,则可以在没有“call”前缀的情况下访问该字段(在问题“call.raw”中)。然后映射将如下所示:

    {
    'station': {
       "properties" :{
           'id': {'type': 'integer'},
           'call': {'type': 'multi_field', 
                    'path' : 'just_name',
                    'fields' : {
                               'call': {'type': 'string', 'analyzer': 'whitespace'},
                               'raw': {'type': 'string', 'index': 'not_analyzed'}
                               }
                    }
        }
    }
    

    }

    不幸的是,这只是一种解决方法。也许其他人有更好的主意?

    【讨论】:

      猜你喜欢
      • 2014-02-06
      • 2017-03-11
      • 1970-01-01
      • 2023-03-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多