栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

加入elasticsearch索引,同时匹配嵌套/内部对象中的字段

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

加入elasticsearch索引,同时匹配嵌套/内部对象中的字段

清除索引(如果有)

curl -XDELETE "http://example.com:9200/currencylookup/"curl -XDELETE "http://example.com:9200/currency/"

创建查找表

curl -XPUT http://example.com:9200/currencylookup/type/2 -d '{ "conv" : [ {  "currency":"usd","username":"abc", "location":"USA" }, {  "currency":"inr", "username":"def", "location":"India" },{  "currency":"IDR", "username":"def", "location":"Indonesia" }]}'

让我们放一些虚拟文档

curl -XPUT "http://example.com:9200/currency/type/USA" -d '{ "amount":"100", "currency":"usd", "location":"USA" }'curl -XPUT "http://example.com:9200/currency/type/JPY" -d '{ "amount":"50", "currency":"JPY", "location":"JAPAN" }'curl -XPUT "http://example.com:9200/currency/type/INR" -d '{ "amount":"50", "currency":"inr", "location":"INDIA" }'curl -XPUT "http://example.com:9200/currency/type/IDR" -d '{ "amount":"30", "currency" : "IDR", "location": "Indonesia" }'

是时候检查输出了

curl http://example.com:9200/currency/_search?pretty -d '{   "query" : { "filtered" : {   "filter" : {     "terms" : {       "currency" : {         "index" : "currencylookup",         "type" : "type",         "id" : "2",         "path" : "conv.currency"       },       "_cache_key" : "currencyexchange"     }   } }   } }'

结果

# curl http://example.com:9200/currency/_search?pretty -d '{   "query" : { "filtered" : {   "filter" : {     "terms" : {       "currency" : {         "index" : "currencylookup",         "type" : "type",         "id" : "2",         "path" : "conv.currency"       },       "_cache_key" : "currencyexchange"     }   } }   } }'{  "took" : 2,  "timed_out" : false,  "_shards" : {    "total" : 5,    "successful" : 5,    "failed" : 0  },  "hits" : {    "total" : 2,    "max_score" : 1.0,    "hits" : [ {      "_index" : "currency",      "_type" : "type",      "_id" : "INR",      "_score" : 1.0,      "_source":{ "amount":"50", "currency":"inr", "location":"INDIA" }    }, {      "_index" : "currency",      "_type" : "type",      "_id" : "USA",      "_score" : 1.0,      "_source":{ "amount":"100", "currency":"usd", "location":"USA" }    } ]  }}

结论

大写字母是罪魁祸首。

您会看到 ‘IDR’ 是大写字母,因此匹配失败,并且即使在 ‘JPY’中 也没有查找,因为它是大写字母。

交叉匹配值必须为小写字母或数字,例如

例如:

  • abc
  • 1abc


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/368073.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号