Elasticsearch and NEST: Filtering with Lookups

[亡魂溺海] 提交于 2019-12-25 06:58:11

问题


I'm using Elasticsearch 1.7.x (and NEST 1.7.2) and trying to take advantage of filtering with lookups as documented here: Terms Filter Lookup. I'm able to craft the JSON by hand for the request I desire and execute it using Sense. Works great, awesome feature! However, in the NEST library, I don't see a way to create such a terms clause. For example, from the link referenced above, I can do something like:

"terms" : {
   "proteins" : {
      "index" : "microarrays",
      "type" : "experiment",
      "id" : "experiment1234",
      "path" : "upregulated_proteins"
   },
   "_cache_key" : "experiment_1234"
}

Is there a way to build this query using NEST? If not, is there a way I can inject some JSON into a NEST query as I'm building it? I don't know if NEST 2.x+ supports this but upgrading to ES 2.x is a longer term plan for us and I'd like to leverage functionality that is already available in ES 1.7.


回答1:


Awesome, I've already received an answer from Greg Marzouka of Elastic! He says:

It's mapped as TermsLookup() or TermsLookupFilter in 1.x. Check out the unit tests for some examples.

client.Search<Paper>(s => s
   .Query(q => q
      .Filtered(fq => qf
         .Filter(f => f
            .CacheKey("experiment_1234")
            .TermsLookup(t => t
               .Lookup<Protein>(p => p.UnregulatedProteins, "experiment1234", "microarrays", "experiment") 
            )
         )
      )
   ));

In 2.x it's a little more aligned with the ES query DSL.



来源:https://stackoverflow.com/questions/37402414/elasticsearch-and-nest-filtering-with-lookups

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!