0

嗨,这是我的索引详细信息:

PUT shingle_test
{
  "settings": {
    "analysis": {
      "analyzer": {
        "evolutionAnalyzer": {
          "tokenizer": "standard",
          "filter": [
            "standard",
            "custom_shingle"
          ]
        }
      },
      "filter": {
        "custom_stop": {
            "type": "stop",
            "stopwords": "_english_"
        },
        "custom_shingle": {
            "type": "shingle",
            "min_shingle_size": "2",
            "max_shingle_size": "10",
            "output_unigrams": false
        }
      }
    }
  }, 
  "mappings": {
    "legacy" : {
      "properties": {
        "name": {
          "type": "text",
          "fields": {
            "shingles": {
              "type": "text",
              "analyzer": "standard",
              "search_analyzer": "evolutionAnalyzer"
            },
            "as_is": {
              "type": "keyword"
            }
          },
          "analyzer": "standard"
        }
      }
    }
  }
}

添加了 2 个文档

PUT shingle_test/legacy/1
{
  "name": "Chandni Chowk 2 Banglore"
}

PUT shingle_test/legacy/2
{
  "name": "Chandni Chowk"
}

如果我这样做,则不会返回任何内容,

GET shingle_test/_search
{
  "query": {
    "match": {
      "name": {
        "query": "Chandni Chowk",
        "analyzer": "evolutionAnalyzer"
      }
    }
  }
}

在网上看了所有可能的解决方案,没有得到任何解决方案。

此外,如果我执行“output_unigrams”:true,那么它就像匹配查询一样工作并给出结果。

我想要实现的目标:

拥有这些文件:

  1. Chandni Chowk 2班加罗尔
  2. Chandni Chowk
  3. CCD班加罗尔
  4. 伊斯塔沙瓦玛和印度比尔亚尼
  5. 伊斯塔

因此,搜索“Chandni Chowk 2 Bangalore”应该返回 1, 2

搜索“Chandni Chowk”应该返回 1, 2

搜索“Istah shawarma and biryani”应该返回 4、5

搜索“Istah”应该返回 4, 5

搜索“CCD Bangalore”应返回 3

注意:搜索关键字将始终与文档中 name 字段的值完全相同 例如:在此特定索引中,我们可以查询“Chandni Chowk 2 Bangalore”、“Chandni Chowk”、“CCD Bangalore”、“Istah shawarma and biryani” ”、“伊斯塔”。不会在该索引上查询“CCD”。

4

1 回答 1

1

Analyzer参数指定在索引或搜索文本字段时用于文本分析的分析器。

将您的索引映射修改为

{
  "settings": {
    "analysis": {
      "analyzer": {
        "evolutionAnalyzer": {
          "tokenizer": "standard",
          "filter": [
            "standard",
            "custom_shingle"
          ]
        }
      },
      "filter": {
        "custom_stop": {
            "type": "stop",
            "stopwords": "_english_"
        },
        "custom_shingle": {
            "type": "shingle",
            "min_shingle_size": "2",
            "max_shingle_size": "10",
            "output_unigrams": true         // note this
        }
      }
    }
  }, 
  "mappings": {
    "legacy" : {
      "properties": {
        "name": {
          "type": "text",
          "fields": {
            "shingles": {
              "type": "text",
              "analyzer": "evolutionAnalyzer",         // note this
              "search_analyzer": "evolutionAnalyzer"
            },
            "as_is": {
              "type": "keyword"
            }
          },
          "analyzer": "standard"
        }
      }
    }
  }
}

并且,修改后的搜索查询将是

{
  "query": {
    "match": {
      "name.shingles": {
        "query": "Chandni Chowk"
      }
    }
  }
}

搜索结果:

"hits": [
      {
        "_index": "66127416",
        "_type": "_doc",
        "_id": "2",
        "_score": 0.25759193,
        "_source": {
          "name": "Chandni Chowk"
        }
      },
      {
        "_index": "66127416",
        "_type": "_doc",
        "_id": "1",
        "_score": 0.19363807,
        "_source": {
          "name": "Chandni Chowk 2 Banglore"
        }
      }
    ]
于 2021-02-10T01:52:59.723 回答