简体   繁体   中英

Convert Elasticsearch Query to NEST

Hi I have a query for elastic search, that I would like to convert to NEST, so I can use this with c#

"query": {
    "constant_score" : {
        "filter" : {
             "bool" : {
                "must" : [
             { "term" : { "Week.keyword": "1712" } },
             { "term" : { "CountAsFailure.keyword": "TRUE" } },
             { "term" : { "Weekday.keyword": "1" } }                 
                ]
            }
        }
    }
}

You might try:

Query(q => q.ConstantScore(cs => cs.Filter(
                f => f.Bool(b => b.Must(m => m.Term("Week.keyword", "1712") &&
                                             m.Term("CountAsFailure.keyword", "TRUE") &&
                                             m.Term("Weekday.keyword", "1"))))))

Or:

Query(q => q.ConstantScore(cs => cs.Filter(
                            f => f.Term("Week.keyword", "1712") && 
                                 f.Term("CountAsFailure.keyword", "TRUE") &&
                                 f.Term("Weekday.keyword", "1"))))

A similar approach worked for me. I found this from https://discuss.elastic.co/t/convert-dsl-query-to-nest-net/93527/4

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM