4

Is there a guide to writing the ES queries - what to do, what to avoid, this sort of stuff. The official site describes all various ways to search, but provides little giudance as to when select what.

In my particular instance I have a list of providers, each one has a name an address and a number of IDs. I want to give the user a box he can type in anything he knows about the provider and run search based on whatever is provided. Essentially I would like to match every word from the box against the records (documents) in the index.

For the end user this should look like a simple keyword search.

Matching should cover exact matches, wild card matches, phonetic matches, synonyms (for names). Also some fuzziness should be included too.

The official site describes various ways to do that, but how to combine them together? For instance to support wild card search do I use wild card query, or do I index it with the NGram and do just text query?

With the SQL queries a certain way to get this sort of information is to check the execution plan for the query. If the SQL optimizer tells you that it will use table scan against a table of considerable size, you know you should change your query, or, may be, add an index. AFAIK there is no equivalent for this powerful feature in ES and I am not even sure if it is possible to build it.

But at least some generic considerations...? Pretty please...

4

2 回答 2

2

做事没有最好的方法,因为很多时候这取决于您要索引的内容,以及如何将数据映射到 Elasticsearch 中的变量。

您应该注意的一些经验法则:

一个。Elasticsearch 中的分面查询按顺序工作:

{   
 "query": {
   // data will be searched from this block first //
 }, "facets": {
   // after the data is received, it will be processed into facets //
 }
}

因此,如果您的查询规模很大,您将通过分面进一步减慢查询速度。监控查询的结果。

湾。过滤器与查询

过滤器执行查询的子集,这意味着它将获取查询的全部结果,然后过滤掉您想要的或不想要的。

查询通常是直接搜索数据。

因此,如果您可以在进行过滤之前使您的查询尽可能具体,它应该会产生更快的结果。

C。查询被缓存;一次又一次地运行它们通常会产生更快的响应。如果您总是要使用相同的查询集, Warmers API应该能够让您的查询更快

同样,所有这些都是经验法则,不能严格遵循,因为您对特定变量的索引会影响处理时间。字符串不同于长类型,带有分析器的字符串不同于非分析器。您需要做的可能是对您的查询进行试验以获得更好的判断。

于 2013-01-26T05:45:32.193 回答
0

上面的一个更正 - 过滤器可以被 ES 缓存,而不是查询。查询执行相关性评分和全文搜索的额外步骤。因此,建议在不需要使用过滤器进行全文搜索的地方。

此外,使用正确的索引值(not_analyzed、no、analyzed)设计您的映射

于 2014-11-04T08:53:30.987 回答