Multi Terms search NEST C#

丶灬走出姿态 提交于 2019-12-10 03:22:29

问题


I want to do a search matching multiple values ( an array of values ) like this :

var result1 = _client.Search<type1>(s => s
            .Fields(f => f.trip_id)
            .Query(q => q
                .Terms(t => t.arg1, value1)).Take(_allData))
                .Documents.Select(d => d.arg2).ToArray();

var result2 = _client.Search<type2>(s => s
                      .Query(q => q
                          .Terms(t => t.arg3, result1))
                          .Take(_allData)
                          ).Documents.Select(s => s.ar3).ToList();

How can I do ? I was thinking about facets but I don't see how I can do it. The only way for now that works is with a foreach iterator which is not really effective...

Thanks for your help.


回答1:


You can express multiple queries like so:

.Query(q=>q.Terms(t=>t.arg3, result1) && q.Terms(t=>t.arg1, value1))

Be sure to read the documentation on writing queries to discover all the good stuff NEST has to offer.




回答2:


Orelus, I'd like to use your solution with

.And( af=>af.Term(...), af=>af.Term(...) )

I don't understand where this fits, here's an example of my non-working filter

var results = client.Search<music>(s => s
    .Query(q => q
        .Filtered(f => f.
            Filter(b => b.Bool(m => m.Must(
                t => t
                    .Term(p => p.artist, artist)
                     && t.Term(p2 => p2.year, year)
                )
                )
            )
        )
    )
    );


来源:https://stackoverflow.com/questions/19213874/multi-terms-search-nest-c-sharp

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