没有从嵌套c#elasticsearch查询返回的结果

时间:2016-06-29 06:05:39

标签: c#-4.0 elasticsearch nest

我正在索引附件字段。意义上的POST查询返回预期的结果集。 我的问题是

POST /mydocs/_search
{
  "query" : {
    "bool" : {
        "must" : [
            { "match" : { "file.content":"abc"} },
            { "match":{"otherDetails":"asd"}},
            { "match" : { "filePermissionInfo.accountValue" : "xyz"} }
        ]
    }
  }
 }

我需要将它转换为c#Nest代码。我尝试转换它,但它没有返回任何结果,即使它包含数据。如果我删除

m.Match(mt1 => mt1.Field(f1 => f1.File.Coontent).Query(queryTerm)) 

从下面的内容中,它返回一个结果集。附件领域有问题吗?

 client.Search<IndexDocument>(s => s
                            .Index("mydocs")
                            .Query(q => q
                            .Bool(b => b
                            .Must(m =>
                            m.Match(mt1 => mt1.Field(f1 => f1.File.Coontent).Query(queryTerm)) &&
                            m.Match(mt2 => mt2.Field(f2 => f2.FilePermissionInfo.First().SecurityIdValue).Query(accountName)) &&
                                 m.Match(mt3 => mt3.Field(f3 => f3.OtherDetails).Query(other)) 
                             )))
                             );    

我的映射是

{
 "mydocs": {
  "mappings": {
     "indexdocument": {
        "properties": {
           "docLocation": {
              "type": "string",
              "index": "not_analyzed",
              "store": true
           },
           "documentType": {
              "type": "string",
              "store": true
           },
           "file": {
              "type": "attachment",
              "fields": {
                 "content": {
                    "type": "string",
                    "term_vector": "with_positions_offsets",
                    "analyzer": "full"
                 },
                 "author": {
                    "type": "string"
                 },
                 "title": {
                    "type": "string",
                    "term_vector": "with_positions_offsets",
                    "analyzer": "full"
                 },
                 "name": {
                    "type": "string"
                 },
                 "date": {
                    "type": "date",
                    "format": "strict_date_optional_time||epoch_millis"
                 },
                 "keywords": {
                    "type": "string"
                 },
                 "content_type": {
                    "type": "string"
                 },
                 "content_length": {
                    "type": "integer"
                 },
                 "language": {
                    "type": "string"
                 }
              }
           },
           "filePermissionInfo": {
              "properties": {
                 "fileSystemRights": {
                    "type": "string",
                    "store": true
                 },
                 "securityIdValue": {
                    "type": "string",
                    "store": true
                 }
              }
           },
           "id": {
              "type": "double",
              "store": true
           },
           "lastModifiedDate": {
              "type": "date",
              "store": true,
              "format": "strict_date_optional_time||epoch_millis"
           },
           "otherDetails": {
              "type": "string"
           },
           "title": {
              "type": "string",
              "store": true,
              "term_vector": "with_positions_offsets"
           }
        }
     }
  }
  }
 }

1 个答案:

答案 0 :(得分:0)

看起来查询尚未正确转换为NEST。在查询中

"filePermissionInfo.accountValue"

但在NEST查询中,您只有

f2 => f2.FilePermissionInfo

只会导致filePermissionInfo。您需要将其更改为

f2 => f2.FilePermissionInfo.AccountValue