0

我是弹性搜索的新手,我正在使用 JAVA API。以下是我面临的问题。

下面是设置,我更新了

"settings" : {
  "index.settings.analysis.tokenizer.str_search_tokenizer.max_gram" : "5",
  "index.settings.analysis.tokenizer.str_search_tokenizer.token_chars.1" : "digit",
  "index.settings.analysis.tokenizer.str_search_tokenizer.min_gram" : "2",
  "index.settings.analysis.analyzer.str_search_analyzer.tokenizer" : "str_search_tokenizer",
  "index.settings.analysis.tokenizer.str_search_tokenizer.token_chars.0" : "letter",
  "index.settings.analysis.tokenizer.str_search_tokenizer.type" : "edgeNGram",
  "index.number_of_shards" : "1",
  "index.number_of_replicas" : "2",
  "index.version.created" : "900299"
}

索引来源:

"_source" : {"message":"This message is sample of maximization","messageId":1}

我搜索消息的代码:

QueryBuilder queryBuilder = QueryBuilders.fuzzyLikeThisQuery("message").likeText("maximizat").analyzer("str_search_analyzer");
FilterBuilder builder = FilterBuilders.queryFilter(queryBuilder);
System.out.println(builder);
SearchResponse response = client.prepareSearch(indexName).setTypes(typeName).setSearchType(SearchType.DFS_QUERY_THEN_FETCH).setFilter(builder).execute().actionGet();
System.out.println(response.getHits().getTotalHits());

当我提供像“maximizati”、“maximizatio”、“maximization”这样的文本时 - 结果会很好。

如果我提供的搜索文本少于 10 个字符,则没有结果。

我需要在 elasticsearch.yml 文件中更新任何更改吗?或者我的设置 JSON 或搜索查询有什么问题?

4

0 回答 0