How do you debug your Nest queries?

前端 未结 8 1926
失恋的感觉
失恋的感觉 2021-02-05 14:02

I\'m new to Nest, and I very likely am not creating my query like I think I am. My question is more along the lines of teach a man to fish rather than give me a fish. However,

8条回答
  •  名媛妹妹
    2021-02-05 14:27

    Really easily. If this is my code that searches:

    var results = client.Search(s => s.AllIndices()
        .Query(q =>
                q.Term(p => p.LastName, searchItem.LastName)
                && q.Term(p => p.FirstName, searchItem.FirstName)
                && q.Term(p => p.ApplicationCode, searchItem.ApplicationCode)
                )
        .Size(1000)
        );
    var list = results.Documents.ToList();
    

    I then set a breakpoint on the line above. Then, in Visual Studio Immediate Window, I enter this:

    ?results.ConnectionStatus
    

    and it gives me this:

    {StatusCode: 200, 
        Method: POST, 
        Url: http://localhost:9200/_all/searchitem/_search, 
        Request: {
      "size": 1000,
      "query": {
        "bool": {
          "must": [
            {
              "term": {
                "lastName": {
                  "value": "carr"
                }
              }
            },
            {
              "term": {
                "firstName": {
                  "value": "adrian"
                }
              }
            }
          ]
        }
      }
    }
    

    Hope this helps.

提交回复
热议问题