【问题标题】:Filter inside nested ComplexTypes在嵌套的 ComplexTypes 中过滤
【发布时间】:2021-10-19 19:27:02
【问题描述】:

我正在尝试根据 tagdata/tags/tag 的值进行过滤。对我有什么想法吗?基本上我只想选择标签文本与特定字符串匹配的文档。谢谢!

过滤器:

search=*&$filter=tagdata/tags/any(tag: tagdata/tags/tag eq 'text1')

错误:

Invalid expression: The parent value for a property access of a property 'tag' is not a single value. Property access can only be applied to a single value.

我有一个如下所示的 ComplexType 定义:

{
      "name": "tagdata",
      "type": "Edm.ComplexType",
      "analyzer": null,
      "synonymMaps": [],
      "fields": [
        {
          "name": "tags",
          "type": "Collection(Edm.ComplexType)",
          "analyzer": null,
          "synonymMaps": [],
          "fields": [
            {
              "name": "tagid",
              "type": "Edm.Int64",
              "facetable": false,
              "filterable": true,
              "retrievable": true,
              "sortable": false,
              "analyzer": null,
              "indexAnalyzer": null,
              "searchAnalyzer": null,
              "synonymMaps": [],
              "fields": []
            },
            {
              "name": "tag",
              "type": "Edm.String",
              "facetable": true,
              "filterable": true,
              "key": false,
              "retrievable": true,
              "searchable": true,
              "sortable": false,
              "analyzer": "en.lucene",
              "indexAnalyzer": null,
              "searchAnalyzer": null,
              "synonymMaps": [],
              "fields": []
            }
          ]
        }
      ]
    },

数据如下:

{
  "tags": [
    {
      "tagid": 83,
      "tag": "text1"
    },
    {
      "tagid": 29,
      "tag": "text2"
    },
    {
      "tagid": 69,
      "tag": "text3"
    },
    {
      "tagid": 115,
      "tag": "text4"
    }
  ]
}

【问题讨论】:

    标签: azure-cognitive-search


    【解决方案1】:

    这应该可行:

    search=*&$filter=tagdata/tags/any(t: t/tag eq 'text1')
    

    any lambda 表达式视为tags 集合的循环,其中冒号后面的标识符是循环变量。该变量属于复杂类型,因此您可以使用斜杠访问其属性。

    【讨论】:

    • 非常感谢布鲁斯,这很有帮助!像冠军一样工作!总体而言,对 Azure 认知搜索非常满意。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-02-01
    • 2021-11-07
    • 1970-01-01
    • 2014-09-18
    • 1970-01-01
    • 2013-08-26
    • 2020-10-15
    相关资源
    最近更新 更多