简体   繁体   English

弹性搜索_all索引

[英]Elastic search over _all index

I did not get THIS example that why the following two queries returned 12 as result count? 我没有得到这个例子,为什么下面的两个查询返回12作为结果计数? Post explains saying that the way data is indexed in _all is different. Post解释说_all数据索引方式不同。 But it does not go about explaining it. 但这并不能解释它。 Can someone please help me understand this. 有人可以帮我理解这一点。

GET /_search?q=2014              # 12 results
GET /_search?q=2014-09-15        # 12 results !

Suppose you have a documents like this: { "name": "John Doe", "occuptation": "Farmer", "favorite_ice_cream": "chocolate" }', { "name": "Jane Doe", "occuptation": "Doctor", "favorite_ice_cream": "vanilla" }' 假设您有一个像这样的文档: { "name": "John Doe", "occuptation": "Farmer", "favorite_ice_cream": "chocolate" }', { "name": "Jane Doe", "occuptation": "Doctor", "favorite_ice_cream": "vanilla" }'

And also suppose that the favorite ice cream field is non analyzed. 并且还假设未分析喜爱的冰淇淋领域。 Non analyzed fields are highly cachable and easy to perform aggregations on (so it's very easy to count how many people like chocolate ice cream, for example, vs vanilla). 未经分析的字段具有很高的可缓存性,并且易于在上面进行汇总(因此,很容易计算出有多少人喜欢巧克力冰淇淋,例如香草冰淇淋)。 But non analyzed fields are not searchable by default. 但是默认情况下无法搜索非分析字段。

But... by default Elasticsearch takes all the fields in a document, crams them together into an _all field, and analyzes them in Lucene. 但是...默认情况下,Elasticsearch会获取文档中的所有字段,将它们塞在一起成为_all字段,然后在Lucene中进行分析。 So, for the first document, Elastic will analyze the string "John Doe Farmer chocolate" and for the second field, Elasticsearch will analyze "Jane Doe Doctor vanilla." 因此,对于第一个文档,Elastic将分析字符串“ John Doe Farmer Chocolate”,而在第二个字段中,Elasticsearch将分析“ Jane Doe Doctor vanilla”。 As a consequence of this, when you submit a query like the one you did above, you can (for example) search for GET /_search?q=chocolate and see that John Doe likes chocolate ice cream. 结果,当您像上面一样提交查询时,您可以(例如)搜索GET /_search?q=chocolate并看到John Doe喜欢巧克力冰淇淋。 You could also submit a Query string query ( https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-query-string-query.html ) to search the _all field and still figure out who likes chocolate. 您还可以提交查询字符​​串查询( https://www.elastic.co/guide/zh-cn/elasticsearch/reference/current/query-dsl-query-string-query.html )以搜索_all字段并仍然可以确定喜欢巧克力的人 You could not, however, use a match query against the favorite ice cream field... after all, we told Lucene not to analyze that field. 但是,您不能对最喜欢的冰淇淋字段使用匹配查询...毕竟,我们告诉Lucene不要分析该字段。 You could, however, use a filter on the field and bring back all the documents for which favorite_ice_cream is equal to chocolate. 但是,您可以在该字段上使用过滤器,并带回所有其favorite_ice_cream等于Chocolate的文档。

It's kind of rough to get used to at first... but the docs are good and not confusing so long as you make sure you keep an eye on which version of the docs you're reading. 刚开始习惯有点困难...但是这些文档很好,并且不会令人困惑,只要您确保时刻关注正在阅读的文档的版本即可。

Also, if it helps, I like to think of the _all field as sort of like get out of jail free card. 另外,如果有帮助,我想把_all字段想像成摆脱监狱的卡。 A lot of times I might choose not to analyze a field because I'll want to run aggregations on it or apply filters. 很多时候,我可能会选择不分析字段,因为我想在该字段上运行聚合或应用过滤器。 And while I usually recall which value I need for a filter, sometimes it's useful to be able to submit a search to the _all field and make sure... So for example if I can't recall if my "country" field has "United States" or "Unites States of America" as the value for the US, I can quickly perform a query against the _all field, look at a few documents, and then pick the appropriate filter value. 虽然我通常会记得需要使用过滤器的值,但有时可以将搜索提交到_all字段并确保...很有用。因此,例如,如果我不记得我的“国家/地区”字段包含“美国”或“美国合众国”作为美国的值,我可以快速针对_all字段执行查询,查看一些文档,然后选择适当的过滤器值。

Another way that I've used the _all field is in full text search in which I want to boost matches on certain fields much higher, but I also want to search all of the fields in the document in case something happens to match. 我使用_all字段的另一种方式是在全文搜索中,在其中我希望提高某些字段上的匹配程度,但是我还想搜索文档中的所有字段,以防碰巧匹配。 A query string query against _all works great in those circumstances. 在这种情况下,针对_all的查询字符串查询非常有用。

You can learn more about the _all field here: https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-all-field.html 您可以在此处了解有关_all字段的更多信息: https ://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-all-field.html

Hope this is enough to get you started... you probably don't want to submit simple queries the way you are. 希望这足以让您入门...您可能不想按照自己的方式提交简单的查询。 Probably, you're gonna want to submit POST requests that utilize the full query DSL. 可能是,您将要提交利用完整查询DSL的POST请求。 You can learn more about that here: https://www.elastic.co/guide/en/elasticsearch/reference/current/query-filter-context.html 您可以在此处了解更多信息: https : //www.elastic.co/guide/en/elasticsearch/reference/current/query-filter-context.html

Best of luck! 祝你好运!

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

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