首页 > 解决方案 > 嵌套弹性搜索文档上的不同值

问题描述

我在我的 ES 索引上使用以下映射。我试图为给定的模糊或完全匹配的嵌套文档找到不同的值

PUT test_index
{
  "settings": {
    "index": {
      "max_ngram_diff": 40
    },
    "analysis": {
      "char_filter": {
        "my_char_filter": {
          "type": "mapping",
          "mappings": [
            "- => "
          ]
        }
      },
      "analyzer": {
        "autocomplete": {
          "char_filter": [
            "my_char_filter"
          ],
          "tokenizer": "whitespace",
          "filter": [
            "lowercase",
            "autocomplete"
          ]
        },
        "autocomplete_search": {
          "char_filter": [
            "my_char_filter"
          ],
          "tokenizer": "whitespace",
          "filter": [
            "lowercase"
          ]
        }
      },
      "filter": {
        "autocomplete": {
          "type": "ngram",
          "min_gram": 2,
          "max_gram": 40
        }
      }
    }
  },
  "mappings": {
    "properties": {
      "accountname": {
        "type": "text",
        "analyzer": "autocomplete",
        "search_analyzer": "autocomplete_search"
      }
    }
  }
}

样本文件

PUT test_index/_doc/1
{
   "identifier": {
    "bankid": 1,
    "name": "dan",
    "accounts": [
      {
        "accountid": "7868",
        "accountname": "dan bruno - Gustave"
      },
      {
        "accountid": "34535",
        "accountname": "dan bruno martin"
      }
      ,
      {
        "accountid": "986",
        "accountname": "sammy darren"
      }
    ]
   }
}

PUT test_index/_doc/2
{
   "identifier": {
    "bankid": 2,
    "name": "dan",
    "accounts": [
      {
        "accountid": "999",
        "accountname": "gray bruno"
      },
      {
        "accountid": "555",
        "accountname": "darren bruno"
      }
      ,
      {
        "accountid": "666",
        "accountname": "mitch marshal"
      }
    ]
   }
}

用于模糊搜索的搜索查询以查找与 Dan 匹配的帐户名称的帐户 ID

Expected Output - Account Id - 7868,34535
Actual Output - Account Id - 7868,34535,986

 get  test_index/_search
{
    "_source" : {
    "includes" : [
      "identifier.accounts.accountid"
    ]},
  "size":1000,
  "query": {
    "match": {
      "identifier.accounts.accountname": "dan"
    }
  }
}

用于模糊搜索的搜索查询以查找与 Dan 匹配的帐户名称的帐户 ID

Expected Output - Account Id - 666
Actual Output - Account Id - 666,555,999

 get  test_index/_search
{
    "_source" : {
    "includes" : [
      "identifier.accounts.accountid"
    ]},
  "size":1000,
  "query": {
    "match": {
      "identifier.accounts.accountname": "mitch marshal"
    }
  }
}

有人可以帮助了解模糊和精确搜索如何在嵌套类型上工作

标签: elasticsearchelasticsearch-nested

解决方案


推荐阅读