简体   繁体   English

如何通过Elasticsearch Java API使用Lucene分析器

[英]How to use lucene analyzers with Elasticsearch java API

I want to build elastisearch queries using JAVA API. 我想使用JAVA API构建elastisearch查询。 I want to know how to can use Lucene analyzers in elasticsearch java programs. 我想知道如何在Elasticsearch Java程序中使用Lucene分析器。 I have checked QueryBuilders and tried to use analyzers directly as below. 我已经检查了QueryBuilders并尝试如下直接使用分析器。

QueryBuilder builder = QueryBuilders.matchQuery(searchString, fields).analyzer("porterstem");

But, it turned out to be wrong. 但是,事实证明这是错误的。 If any one tried it, could you please give me some information? 如果有人尝试过,请给我一些信息吗?

You should define your analyzer in mapping. 您应该在映射中定义分析器。 So the analyzer will be used at index time and at query time. 因此,分析器将在索引时间和查询时间使用。

ANALYZERS are used to analyze the documents that your are indexed. ANALYZERS用于分析被索引的文档。 Analysis means it Ll split,the text in to tokens, normalize it, and also Lower case your indexed doc text. 分析意味着将其拆分,将文本放入标记中,对其进行规范化,还对索引的文档文本进行小写形式。 This analysis process Ll b more helpful while you search and searching will be faster.. 当您进行搜索时,此分析过程Llb将更有用,并且搜索将更快。

You can mention analyzer while you query . 您可以在查询时提及分析器。 But analyze the stored documents during query time. 但是在查询期间分析存储的文档。 Ll b expensive. Ll b昂贵。 So analyze the document during indexing time. 因此在索引期间分析文档。 ES will analysis the doc during indexed and query time will b less and faster result. ES将在建立索引期间分析文档,而查询时间将减少和更快地得到结果。 So mention analyzers in mapping and searching efficiently.. 因此,请在有效地映射和搜索中提及分析器。

For more information about analyzer refer https://lucene.apache.org/core/4_0_0/core/org/apache/lucene/analysis/Analyzer.html 有关分析仪的更多信息,请参见https://lucene.apache.org/core/4_0_0/core/org/apache/lucene/analysis/Analyzer.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM