您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

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

加入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" }
    } ]
  }
}

大写字母是罪魁祸首。

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

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

例如:

其他 2022/1/1 18:19:13 有538人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶