我在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"}}}}'
答案 0 :(得分:1)
这是一个好的开始
请改为尝试:
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*"
}
}
]
}
}
}