我已经在elasticsearch模块中存储了一些数据,结构非常简单。
[
{
"country_id":1,
"city_id":12,
"city_name":"Kolkata"
},
{
"country_id":1,
"city_id":55,
"city_name":"Delhi"
},
{
"country_id":2,
"city_id":18,
"city_name":"Las Vegas"
},
{
"country_id":3,
"city_id":22,
"city_name":"Sydney"
}
]我需要一个类似这样的搜索查询
"Select * from table_name where country_id = 1 and city_name like %k%"如果有任何人在那里,请帮助我找到上述sql查询的确切elasticsearch查询。
我已经尝试了这个查询,但它产生了错误。
curl -XGET "http://xxx.xxx.xxx.x:9200/xxxx/location_details/_search?size=10" -d '{"query":{"bool":{"must":{"term":{"country_id":"101"}}},{"match_phrase":{"city_name":"a"}}}}'发布于 2016-08-05 19:34:09
这是一个很好的开始
试着这样做:
curl -XPOST "http://xxx.xxx.xxx.x:9200/xxxx/location_details/_search" -d '{
"size": 10,
"query": {
"bool": {
"must": [
{
"term": {
"country_id": "101"
}
},
{
"query_string": {
"query": "city_name:*a*"
}
}
]
}
}
}https://stackoverflow.com/questions/38788200
复制相似问题