小编典典

ElasticSearch:如何在一个或多个索引的所有类型的任何字段中搜索值?

elasticsearch

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

my_index_1

  • 组织机构
  • 角色
  • 技能

my_index_2

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

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

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

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

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

预先感谢您提供的任何帮助。


阅读 824

收藏
2020-06-22

共1个答案

小编典典

无论是query_string查询match查询将是你在找什么。

query_string如果未指定,将使用特殊_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


更新:

由于该_all字段在6.0中已弃用,因此解决方案是实现自定义所有字段

2020-06-22