如何使用elasticsearch中的URI search搜索某些数据?
我想进行类似于SQL LIKE
功能的搜索
我试过
http://****/billing_master/_search?q=CUST_NAME:Komplek*
我希望结果如下:
{
"_index": "billing_master",
"_type": "90000019",
"_id": "C20110325000809_371",
"_score": 1,
"_source": {
"ALAMAT": "Komplek Ruko Jl. By pass Ngurah Rai No.257 Suwung Kangin Denpasar Selatan",
"CUST_NAME": "PT. Sobek Bali Utama (Cp. I Made Antara)",
"ANI": "082897030385",
"CUST_ID": "C20110325000809_371",
"SCGROUP": 39,
"EMAIL": "edps@balisobeks.com,indradewis@balisobeks.com,dewis@balisobeks.com",
"BILLING_ID": "90000019",
"SOFTORHARD": "03",
"HCGROUP": 39
}
}
但实际结果是
{
"took": 3,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 0,
"max_score": null,
"hits": []
}
}
答案 0 :(得分:0)
我不知道你的数据模型,但我会为这种情况建议2个解决方案:
解决方案1 - 为URI创建嵌套类型:
{
"nesttype" : {
"properties" : {
"uri" : {
"type" : "nested" ,
"properties" : {
"host" : { "type" : "string" },
"relativePath" : { "type" : "string" },
"params" : { "type" : "string" },
"paramValues" : { "type" : "string" }
}
}
}
}
}
使用此嵌套类型,您可以创建嵌套查询并搜索字段:“host”为“****”,“relativePath”为“billing_master / _search”,“paraValues”为“CUST_NAME:Komplek”
解决方案2 - 创建未分析的字符串字段:
{
"test" : {
"properties" : {
"uri" : {
"type" : "string" ,
"index" : "not_analyzed"
}
}
}
}
对于这种类型的字段,uri不会拆分为令牌。所以你可以使用通配符查询。
有关详细信息,请参阅分析字段,嵌套字段和嵌套查询。