嗨,我可以用 DateRangeQuery 数组填充 QueryContainer,如下所示

        if (!string.IsNullOrEmpty((item.marriage_date)))
            {
                DateRangeQuery query = new DateRangeQuery();
                query.Field = "marriages.marriage_date";
                query.Name = item.marriage_date;
                query.GreaterThanOrEqualTo = item.marriage_date;
                query.LessThanOrEqualTo = item.marriage_date;

                marriageDateQuerys &= query;
            }

但是当我使用 QueryContainer 使用 MatchQuery/TermQuery 来填充数据时,它并没有发生。
           QueryContainer marriageSpouseFirstNameQuerys = null;


            if (!string.IsNullOrEmpty((item.spouse_first_name)))
            {
                MatchQuery query = new MatchQuery();
                query.Field = "marriages.spouse_first_name";
                query.Name = item.spouse_first_name;
                marriageSpouseFirstNameQuerys &= query;
            }

查询对象是在最后一个 if 条件下创建的,但 marionSpouseFirstNameQuerys 没有填充相同的条件。我什至试过marriageSpouseFirstNameQuerys += query;但没有任何成功

最佳答案

没试过,但你可以试试这样的

              Query = new QueryContainer(new BoolQuery
                    {
                        Must = new List<QueryContainer>
                        {
                            new MatchQuery
                            {
                                //props
                            },
                            new TermQuery
                            {
                                Field = field
                                Value = value
                            },
                        }
                    })

关于elasticsearch - Nest QueryContainer 用法,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/44309285/

10-11 08:40