I have a few ElasticSearch documents, which contain an Array field.
I want to be able to search the whole index
To find the documents which firstly contains the array field,
and if they do, find those documents which contain the value to be searched.
Following is my data -
{
"took" : 633,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 4,
"relation" : "eq"
},
"max_score" : 1.0,
"hits" : [
{
"_index" : "demo",
"_type" : "1",
"_id" : "1",
"_score" : 1.0,
"_source" : {
"name" : "anon",
"nick_name" : "an",
"hobbies" : [
"reading",
"writing"
]
}
},
{
"_index" : "demo",
"_type" : "1",
"_id" : "2",
"_score" : 1.0,
"_source" : {
"name" : "anon2",
"nick_name" : "an2",
"hobbies" : [
"playing",
"studying"
]
}
},
{
"_index" : "demo",
"_type" : "1",
"_id" : "3",
"_score" : 1.0,
"_source" : {
"name" : "anon3",
"nick_name" : "an3",
"hobbies" : [
"playing",
"writing"
]
}
},
{
"_index" : "demo",
"_type" : "1",
"_id" : "4",
"_score" : 1.0,
"_source" : {
"name" : "anon4",
"nick_name" : "an4"
}
}
]
}
}
I want to get those documents whose hobbies array contains "playing" or "studying" value
ie. documents 2 and 3
Following are my data creation queries -
POST /demo/_doc/1
{
"name":"anon",
"nick_name":"an",
"hobbies":["reading","writing"]
}
POST /demo/_doc/2
{
"name":"anon2",
"nick_name":"an2",
"hobbies":["playing","studying"]
}
POST /demo/_doc/3
{
"name":"anon3",
"nick_name":"an3",
"hobbies":["playing","writing"]
}
POST /demo/_doc/4
{
"name":"anon4",
"nick_name":"an4"
}
GET demo/_search
{
"query": {
"match_all": {}
}
}
The following query is able to get me single search, but how can I achieve Or condition?
GET demo/_search
{
"query": {
"match": {
"hobbies": "playing"
}
}
}