加入elasticsearch指数同时匹配嵌套/内对象的字段 [英] Join elasticsearch indices while matching fields in nested/inner objects

查看:1563
本文介绍了加入elasticsearch指数同时匹配嵌套/内对象的字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用术语过滤器查找加入2 elasticsearch指数。我提到 http://www.elasticsearch.org/blog/terms-filter-lookup / 和<一个href=\"http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-terms-filter.html\" rel=\"nofollow\">http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-terms-filter.html.这些例子查找字段像追随者的阵列上。[1,3],并加入工程罚款类似的数据。

I am trying to join 2 elasticsearch indices by using terms filter lookup. I referred to http://www.elasticsearch.org/blog/terms-filter-lookup/ and http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-terms-filter.html. These Examples lookup on an array of fields like "followers" : ["1", "3"] and join works fine for similar data.

我的要求是与现场的加盟对象的数组中。当我向上面的例子,包括对象的数组,我查询失败。
以下是示例数据:

My requirement is to join with a field inside an array of objects. When I extend the above example to include an array of objects, my query fails. Following is the sample data:

PUT /users/user/2 {
   "followers" : [
  {
    "userId":"1",
    "username":"abc",
    "location":"xyz"
   },
   {
    "userId":"3",
    "username":"def",
    "location":"xyz"
   }
}
]
}

PUT /tweets/tweet/1 {
   "user" : "2"
}

PUT /tweets/tweet/2 {
   "user" : "1"
}

我现在正在试图找到由用户2追随者创建鸣叫

I am now trying to find tweets that are created by followers of user 2

POST /tweets/_search {
  "query" : {
"filtered" : {
  "filter" : {
    "terms" : {
      "user" : {
        "index" : "users",
        "type" : "user",
        "id" : "2",
        "path" : "followers.userId"
      },
      "_cache_key" : "user_2_friends"
    }
  }
}
  }
}

我的搜索结果是0以上的查询。我尝试过其他方法2以及1)声明映射期间为嵌套对象追随者对象,并在查询中使用嵌套,2)试图给路径为追随者后添加匹配查询followers.userId。无初见成效。

My search results are 0 for above query. I tried 2 other approaches as well 1)declare the followers object as a nested object during mapping and use "nested" in the query, 2)tried to add a match query for followers.userId after giving path as "followers". None yielded results.

请问对象来过滤查找支持数组?解决我的问题,任何指针将有很大的帮助。

Does terms filter lookup support array of objects? Any pointers to solving my problem would be of great help

推荐答案

清除指数如果您有任何

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

结论

大写字母罪魁祸首这里。

Capital letters are culprit here.

您可以看到的'IDR'是大写的,所以比赛的失败,它和JPY不抬头,即使它在那里它不会已经得到匹配,因为它是上限。

You can see 'IDR' is in caps so the match is failed for it and 'JPY' is not in look up even if it was there it would not have got matched because it is in caps.

交叉配值必须是小写字母或数字像

cross matching values must be in small letters or numbers like

例如:


  • ABC

  • 1ABC

这篇关于加入elasticsearch指数同时匹配嵌套/内对象的字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆