0
我已经索引文件是这样的:如何通过Elasticsearch中的数组字段进行搜索?
[PUT] /my_index/cars/1
{
"color" : "red",
"passengers" : ["John", "Annie", "William"]
}
我试图寻找所有的汽车,其中“约翰”是乘客。
我已经索引文件是这样的:如何通过Elasticsearch中的数组字段进行搜索?
[PUT] /my_index/cars/1
{
"color" : "red",
"passengers" : ["John", "Annie", "William"]
}
我试图寻找所有的汽车,其中“约翰”是乘客。
您可以像任何其他字段一样进行搜索。
-bash-4.2$ curl 'localhost:9200/my_index/_search?pretty=true&q=passengers:John'
{
"took" : 4,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"failed" : 0
},
"hits" : {
"total" : 1,
"max_score" : 0.15342641,
"hits" : [ {
"_index" : "my_index",
"_type" : "cars",
"_id" : "1",
"_score" : 0.15342641,
"_source" : {
"color" : "red",
"passengers" : [ "John", "Annie", "William" ]
}
} ]
}
}
尽管codegrep_admin的答案有用,但我一直在寻找可以更容易操作的东西。
我结束了使用bool
这样的查询:
[GET] /my_index/cars/_search
{
"query": {
"bool": {
"must": [
{ "match": { "passengers": "John" }},
{ "match": { "passengers": "Annie" }}
]
}
}
,如果我想所有的约翰和安妮的? – awavi
只是添加OR条款'q =乘客:约翰或乘客:安妮' –