ElasticSearch:如何在一个或多个索引的所有类型的任何字段中搜索值? [英] ElasticSearch: How to search for a value in any field, across all types, in one or more indices?
问题描述
我有两个索引my_index_1
和my_index_2
.在这些索引中,我具有以下文档类型:
my_index_1
:
- 人
- 组织
- 角色
- 技能
my_index_2
:
- 产品
- 服务
- 专利
- 商标
- 服务标记
每种类型都有不同的字段.
我的问题: 在任何类型甚至跨一个或两个索引的任何类型的字段中查询字符串"abc"的最佳方法是什么? >
我在文档中看不到任何有助于这种搜索的内容.是否有可能看起来像这样:
$ curl -XPOST 'localhost:9200/_search?pretty' -d '
{
"query": { "match": { *: "abc" } }
}'
在此先感谢您提供的任何帮助.
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
,则不能使用通配符
更新:
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屋!