Skip to content

Raw queries joined with NEST QueryContainer do not serialize. #1680

Closed
@JefStat

Description

@JefStat

Combining multiple queries into a single boolean query but the query generated is empty for the queries that are created from a raw string.

With this method call

ConvertQueryToESD("{\"term\":\"fieldname\":\"value\"}"
                  ,null
                  ,a range filter)
    .From(0)
    .Take(50)
    .SortMulti(a sort)
 internal SearchDescriptor<T> ConvertQueryToESD<T>(string queryString, string filterId, List<QueryContainer> filters) where T : class
    {
        var filterQueryString = GetFilter(filterId);
        if (!string.IsNullOrWhiteSpace(filterQueryString))
        {
            var qd = new QueryDescriptor<T>();
            filters.Add(qd.Raw(filterQueryString));
        }
        if (!string.IsNullOrWhiteSpace(queryString))
        {
            var qd = new QueryDescriptor<T>();
            filters.Add(qd.Raw(queryString));
        }
        var sd = new SearchDescriptor<T>();
        sd.Query(q => q.Bool(b => b.Must(filters.ToArray())));
        return sd;
    }

Resulting query is

{
  "from": 0,
  "size": 50,
  "sort": [
    {
      "startTimeLocal": {
        "order": "desc"
      }
    }
  ],
  "query": {
    "bool": {
      "must": [
        {
          "range": {
            "startTimeLocal": {
              "gte": "0001-01-01T00:00:00",
              "lte": "2015-12-22T16:28:22"
            }
          }
        },
        {}
      ]
    }
  }
}

The {} is where I would expect to see the raw term query. Inspecting the SearchDescriptor before the search is ran shows all the expected fields are populated with the correct values. I have also tested only adding the raw string term query without the range filter and the search descriptor serializes as expected

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