ElasticSearch:如何在一个或多个索引的所有类型的任何字段中搜索值? [英] ElasticSearch: How to search for a value in any field, across all types, in one or more indices?

查看:908
本文介绍了ElasticSearch:如何在一个或多个索引的所有类型的任何字段中搜索值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个索引my_index_1my_index_2.在这些索引中,我具有以下文档类型:

my_index_1:

  • 组织
  • 角色
  • 技能

my_index_2:

  • 产品
  • 服务
  • 专利
  • 商标
  • 服务标记

每种类型都有不同的字段.

我的问题: 在任何类型甚至跨一个或两个索引的任何类型的字段中查询字符串"abc"的最佳方法是什么?

我在文档中看不到任何有助于这种搜索的内容.是否有可能看起来像这样:

$ curl -XPOST 'localhost:9200/_search?pretty' -d '
{
  "query": { "match": { *: "abc" } }
}'

在此先感谢您提供的任何帮助.

解决方案

_all字段(如果在default_field中未指定),则效果很好.

curl -XPOST 'localhost:9200/_search?pretty' -d '{
  "query": { "query_string": { "query": "abc" } }
}'

通过match,您也可以指定_all.

curl -XPOST 'localhost:9200/_search?pretty' -d '{
  "query": { "match": { "_all": "abc" } }
}'

请注意,对于query_string,您可以使用通配符,而对于match,则不能使用通配符


更新:

由于在6.0中弃用了_all字段,因此现在的解决方案是实施

I don't see anything in the documentation that facilitates such a search. Is there something that might look like:

$ curl -XPOST 'localhost:9200/_search?pretty' -d '
{
  "query": { "match": { *: "abc" } }
}'

Thanks, in advance, for any help you can offer.

解决方案

Either the query_string query or the match query would be what you're looking for.

query_string will use the special _all field if none is specified in default_field, so that would work out well.

curl -XPOST 'localhost:9200/_search?pretty' -d '{
  "query": { "query_string": { "query": "abc" } }
}'

And with match you can just specify the _all as well.

curl -XPOST 'localhost:9200/_search?pretty' -d '{
  "query": { "match": { "_all": "abc" } }
}'

Note that with query_string you may use wildcards, which you can't with match


UPDATE:

As the _all field was deprecated in 6.0, the solution is now to implement a custom all field

这篇关于ElasticSearch:如何在一个或多个索引的所有类型的任何字段中搜索值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆