I'm using goes library (https://github.com/OwnLocal/goes), which is the wrapper for ElasticSearch in Golang.
In ElasticSearch queries, we can run like this:
{
"query": {
"match": {
"user_id_1": "438018"
}
}
}
and it works.
For golang using goes, you can run it like as:
var query = map[string]interface{}{
"query": map[string]interface{}{
"match": map[string]interface{}{
"user_id_1": "438018",
},
},
}
Here is my question, you can use this query in elasticsearch
{
"query": {
"bool": {
"should": [
{
"match": {
"year": "2016"
}
},
{
"match": {
"frequency": "7"
}
}
]
}
}
}
In the above code, it is the bool should clause written in documentation here (https://www.elastic.co/guide/en/elasticsearch/reference/current/_executing_searches.html)
So, I made query2 to search same way as elastic one.
var query2 = map[string]interface{}{
"query": map[string]interface{}{
"bool": map[string]interface{}{
"should": map[string]interface{}{
"match": map[string]interface{}{
"year": "2016",
},
"match": map[string]interface{}{
"frequency": "7",
},
},
},
},
}
Error: duplicate key "match" in map literal
I am not so familiar with interface on golang.
I hope some has a idea for that. Thanks.
p.s.
Thanks Tranvu Xuannhat :) it helped a lot !
var query2 = map[string]interface{}{
"query": map[string]interface{}{
"bool": map[string]interface{}{
"should": []map[string]interface{}{
map[string]interface{}{
"match": map[string]interface{}{
"year": "2016",
},
},
map[string]interface{}{
"match": map[string]interface{}{
"frequency": "7",
},
},
},
},
},
}
This is what I did finally.