【问题标题】:Set Index Key to Output Field Mapping将索引键设置为输出字段映射
【发布时间】:2020-09-14 01:02:17
【问题描述】:

在我的索引中,我有一个名为id 的字段。在我的浓缩管道中,我计算了一个名为/document/documentId 的值,我试图将其映射到id 字段。但是,此映射似乎不起作用,因为 id 似乎总是一些看起来像哈希的长值。我的所有其他输出字段映射都按预期工作。

索引部分:

{
    'name': 'id',
    'type': 'Edm.String',
    'facetable': false,
    'filterable': true,
    'key': true,
    'retrievable': true,
    'searchable': true,
    'sortable': true,
    'analyzer': null,
    'indexAnalyzer': null,
    'searchAnalyzer': null,
    'synonymMaps': [],
    'fields': []
}

索引器部分:

'outputFieldMappings': [
    {
        'sourceFieldName': '/document/documentId',
        'targetFieldName': 'id'
    }
]

预期值:4b160942-050f-42b3-bbbb-f4531eb4ad7c

实际值:aHR0cHM6Ly9zdGRvY3VtZW50c2Rldi5ibG9iLmNvcmUud2luZG93cy5uZXQvMDNiZTBmMzEtNGMyZC00NDRjLTkzOTQtODJkZDY2YTc4MjNmL29yaWdpbmFscy80YjE2MDk0Mi0wNTBmLTQyYjMtYmJiYi1mNDUzMWViNGFkN2MucGRm0

任何关于如何解决此问题的想法将不胜感激!

【问题讨论】:

    标签: azure-cognitive-search


    【解决方案1】:

    TL;DR - 不能为键使用输出字段映射。只能使用源字段。

    根据 Microsoft 的说法,无法使用输出字段映射设置文档键。显然,在删除文档的情况下存在问题,因此密钥必须直接存在于文档中。

    我最终在 fieldMappings 中使用了映射函数。

     "fieldMappings": [
        {
          "sourceFieldName": "metadata_storage_name",
          "targetFieldName": "filename"
        },
        {
          "sourceFieldName": "metadata_storage_name",
          "targetFieldName": "id",
          "mappingFunction": {
            "name": "extractTokenAtPosition",
            "parameters": {
              "delimiter": ".",
              "position": 0
            }
          }
        }
      ]
    

    由于我的文件名类似于4b160942-050f-42b3-bbbb-f4531eb4ad7c.pdf,因此这最终会正确地将映射映射到我的 ID。

    【讨论】:

      【解决方案2】:

      您可以使用常规字段映射而不是输出字段映射。如果您在 Azure 门户中创建了索引器,则您的键(即“id”,因为在上面的“id”的索引定义中键为真)可能是 base64 编码的(默认情况下选中该选项)。您需要对其进行 base64 解码以获得原始值,或者您可以存储原始值的第二个副本而不对其进行编码(密钥需要进行编码)。后者的做法如下 - 这可以替换您的输出字段映射:

      "fieldMappings": [
        {
          "sourceFieldName": "documentId",
          "targetFieldName": "documentId"
        },
        {
          "sourceFieldName": "documentId",
          "targetFieldName": "id",
          "mappingFunction": {
             "name": "base64Encode"
          }
        }
      ]
      

      请注意,您还需要在索引中添加一个 documentId 字段,因为您也以原始格式存储它。

      {
      'name': 'documentId',
      'type': 'Edm.String',
      'facetable': false,
      'filterable': true,
      'key': false,
      'retrievable': true,
      'searchable': true,
      'sortable': true,
      'analyzer': null,
      'indexAnalyzer': null,
      'searchAnalyzer': null,
      'synonymMaps': [],
      'fields': []
      

      }

      或者,您可以只对 id 值进行 base64 编码(存储时)和解码(检索时)。此键值是 base64 编码的,因此可以安全地用作 Azure 认知搜索文档键。查看https://docs.microsoft.com/azure/search/search-indexer-field-mappings 了解更多信息。

      【讨论】:

      • 不幸的是,这不起作用,因为 fieldMappings 仅适用于我的数据源中存在的列。由于 /document/documentId 是在扩充管道期间计算的,因此我无法使用它
      猜你喜欢
      • 2017-01-30
      • 2014-10-02
      • 2018-04-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-19
      • 1970-01-01
      相关资源
      最近更新 更多