1

The following query in Sense returns the results that I'm looking for, however when I convert it to a NEST query, I always receive 0 results. Where am I going wrong?

GET /event,meeting,executive,list,call/_search
{
  "query": {
    "filtered": {
      "query": {
        "bool": {
          "should": [
            {
              "match": {
                "name": "sample query"
              }
            },
            {
              "match": {
                "agenda": "sample query"
              }
            }
          ]
        }
      },
      "filter": {
        "query": {
          "match": {
            "symbol": "SAMPLESYMBOL"
          }
        }
      }
    }
  }
}

And here is the NEST search descriptor that I'm using that always returns 0 results.

return arg.Indices(new[] { "event", "meeting", "executive", "list", "call" })
    .Size(size)
    .Filter(f => f.Query(qu => qu.Match(m => m.OnField("symbol").Query("SAMPLESYMBOL"))))
    .Query(q => q
        .Bool(b => b
            .Should(
                s => s.Match(m => m.Query(query).OnField("name")),
                s => s.Match(m => m.Query(query).OnField("agenda")))));

1 Answer 1

2

The query that's working in Sense is a filtered query, whereas in NEST you are executing a query besides a filter. That could possibly be the issue.

Try this, which should generate the equivalent JSON to the query you are running in Sense:

.Indices(new[] { "event", "meeting", "executive", "list", "call" })
.Size(size)
.Query(q => q
  .Filtered(f => f
    .Query(qq => qq
      .Bool(b => b
        .Should(s => s.Match(m => m.OnField("name").Query(query)))
        .Should(s => s.Match(m => m.OnField("agenda").Query(query)))
      )
    )
    .Filter(ff => ff
      .Query(qf => qf
        .Match(m => m.OnField("symbol").Query("SAMPLESYMBOL"))
      )
    )
  )
);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.