Skip to content

After upgrading to .12 having issues reusing a QueryDescriptor #579

@lemkepf

Description

@lemkepf

Basically we've been running .9 nest dll's for quite a while now and I recently upgraded the nuget packages to .12. We have a filter we "reuse" it multiple queries but for some reason it's not adding it to the query to elasticsearch anymore.

Here is the query, notice the "createpermissionsfilter".

query.Query(qd => qd
    .Bool(b => b
        .Must(
            q => q.Term(p => p.LocationId, LocationId.ToString())
            //add in permissions filter
            && CreatePermissionsFilter(CurrentUserId, usersToSearch, searchUnassigned, ref q)
        )
        .Should(
        // parent
            a => a.TextPhrasePrefix(p => p.QueryString(term).Boost(1.5).PrefixLength(2).OnField("_all").MaxExpansions(1000)),
            a => a.Text(p => p.QueryString(term).Boost(1.5).PrefixLength(2).OnField("name")),
            a => a.Text(p => p.QueryString(term).Boost(1.5).PrefixLength(2).OnField("primaryContact.fullName")),
            a => a.Text(p => p.QueryString(term).Boost(1.5).PrefixLength(2).OnField("fullAddress").Operator(Operator.and)),
            a => a.Text(p => p.QueryString(term).Boost(1.5).PrefixLength(2).OnField("primaryContact.companyName")),
            // child
            a => a.HasChild<ChildRecord>(fz =>
                 fz.Query(
                    c => c.TextPhrasePrefix(p => p.QueryString(term).Boost(.5).Fuzziness(.1).PrefixLength(2).OnField("_all").MaxExpansions(1000))
                 ).Type("childRecord")
            )
        )
        .MinimumNumberShouldMatch(1)
    )
);

Here is the function we are using for CreatePermissionsFilter:

private static QueryDescriptor<ParentRecord> CreatePermissionsFilter(Guid CurrentUserId, List<Guid> usersToSearch, bool searchUnassigned, ref QueryDescriptor<ParentRecord> filter)
    {
        filter.Bool(c => c.Should(
                        s => s.Terms(p => p.AssignedUsers, usersToSearch.ConvertAll(a => a.ToString()).ToArray()),
                        s => s.Term(p => p.OverrideUsers, CurrentUserId.ToString()),
                        s => s.Term(p => p.Unassigned, "true"),
                        s => s.Term(p => p.Global, "true")
                    )
                    .MinimumNumberShouldMatch(1)
        );
        return filter;
    }

But when this query is run elastic search actually throws an error because part of the query looks like this:

  "query": {
    "bool": {
      "must": [
        {
          "bool": {
            "must": [
              {
                "term": {
                  "locationId": {
                    "value": "ccbfab87-4168-496c-8a7e-b5b7f811397c"
                  }
                }
              },
              {}
            ]
          }
        }
      ],

Notice the {} with nothing in it? That should be my function putting in the filters. Any thoughts on what I'm doing wrong?

Thanks,
Paul

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions