简体   繁体   English

ElasticSearch 6.2:从MySQL自动完成搜索

[英]ElasticSearch 6.2: autocomplete search from MySQL

First at all, I would like to say that I use Elasticsearch and Logstash 6.2 and due the big update, a lot of topics are not compatible. 首先,我想说的是,我使用Elasticsearch和Logstash 6.2,并且由于进行了较大的更新,因此许多主题不兼容。 I looked twice before posting mine. 在发布我的帖子之前,我看了两次。 :) :)

I use MySQL as database and with Logstash 6.2 and JDBC, I transfer automatically my rows in Elasticsearch 6.2. 我使用MySQL作为数据库,并使用Logstash 6.2和JDBC,在Elasticsearch 6.2中自动传输行。 Everything works fine from this side ! 从这一方面,一切都很好!

However, I'm trying to use Elasticsearch as search engine in a Node/Express' project. 但是,我正在尝试将Elasticsearch用作Node / Express'项目中的搜索引擎。 I would like to create an autocomplete searchbar as describes in this tutorial Leveraging the Power of Elasticsearch: Autocomplete and Fuzzy Search . 我想创建一个自动完成搜索栏,如本教程所述, 利用Elasticsearch的功能:自动完成和模糊搜索

The problem is I can't enable auto completion because my data loaded from MySQL are as String and not as Completion type: 问题是我无法启用自动完成功能,因为从MySQL加载的数据是String而不是Completion类型:

Illegal_argument_exception, reason:Field [extid] is not a completion suggest field, status:400 Illegal_argument_exception,原因:字段[extid]不是完成建议字段,状态:400

So for the getSuggestions function, I try this : 因此,对于getSuggestions函数,我尝试这样做:

function getSuggestions(text, size){
   return elasticClient.search({
   index: indexName,
   type: indexType,
   body: {
       suggest: {
           extidSuggester: {
               text: text+'~',
               term: {
                   field: "extid",
                   size: size
               }
           },
           nameSuggester: {
               text: text+'~',
               term: {
                   field: "name",
                   size: size
               }
           }
         }
       }
  });
}

which does not give me autocompletion. 这不会给我自动完成功能。

A solution could be to filter the targeted columns in the Logstash conf and force to the completion's type. 一种解决方案是过滤Logstash conf中的目标列,然后强制使用补全的类型。 Is someone know how to perform that ? 有人知道如何执行吗?

Is there another solution to resolve my problem ? 还有其他解决方案可以解决我的问题吗?

I finally answer myself. 我终于回答了自己。

When I created the mapping, I used a default mapping found on github . 创建映射时,我使用了github上的默认映射。

I added to this mapping the type completion for the needed fields and it resolved my issue. 我在此映射中添加了所需字段的类型完成 ,从而解决了我的问题。

Simple as that ! 就那么简单 !

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

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