繁体   English   中英

如何搜索Elasticsearch索引中附加的文档的内容

[英]How to search a content of a document attached in elasticsearch index

我在elasticsearch中创建了索引为

this.client.CreateIndex("documents", c => c.Mappings(mp => mp.Map<DocUpload>
              (m => m.Properties(ps => ps.Attachment
                                     (a => a.Name(o => o.Document)
                                            .TitleField(t => t.Name(x =>  x.Title).TermVector(TermVectorOption.WithPositionsOffsets))
                                             )))));

附件在索引之前经过base64编码。 我无法搜索任何文档中的内容。 是base64编码会造成任何问题。 谁能帮忙吗?

浏览器响应就像

    {
 "documents": {
   "aliases": {},
   "mappings": {
  "indexdocument": {
    "properties": {
      "document": {
        "type": "attachment",
        "fields": {
          "content": {
            "type": "string"
          },
          "author": {
            "type": "string"
          },
          "title": {
            "type": "string",
            "term_vector": "with_positions_offsets"
          },
          "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"
          }
        }
      },
      "documentType": {
        "type": "string"
      },
      "id": {
        "type": "long"
      },
      "lastModifiedDate": {
        "type": "date",
        "format": "strict_date_optional_time||epoch_millis"
      },
      "location": {
        "type": "string"
      },
      "title": {
        "type": "string"
      }
    }
  }
},
"settings": {
  "index": {
    "creation_date": "1465193502636",
    "number_of_shards": "5",
    "number_of_replicas": "1",
    "uuid": "5kCRvhmsQAGyndkswLhLrg",
    "version": {
      "created": "2030399"
    }
  }
},
"warmers": {}
}
 }

我通过添加分析仪找到了解决方案。

var fullNameFilters = new List<string> { "lowercase", "snowball" };
        client.CreateIndex("mydocs", c => c
              .Settings(st => st
                        .Analysis(anl => anl
                        .Analyzers(h => h
                            .Custom("full", ff => ff
                                 .Filters(fullNameFilters)
                                 .Tokenizer("standard"))
                            )
                            .TokenFilters(ba => ba
                                .Snowball("snowball", sn => sn
                                    .Language(SnowballLanguage.English)))                    
                             ))
                         .Mappings(mp => mp
                         .Map<IndexDocument>(ms => ms
                         .AutoMap()
                         .Properties(ps => ps
                             .Nested<Attachment>(n => n
                                 .Name(sc => sc.File)
                             .AutoMap()
                             ))
                        .Properties(at => at
                        .Attachment(a => a.Name(o => o.File)
                        .FileField(fl=>fl.Analyzer("full"))
                        .TitleField(t => t.Name(x => x.Title)
                        .Analyzer("full")
                        .TermVector(TermVectorOption.WithPositionsOffsets)
                        )))

                        ))                        
                        );

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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