How to search in attachment content?

I ingest pdf files into elastic.
I can successful search in it using Kibana Console.
But at my C# code I don't get any result.
I'm quit sure the problem is syntax of my code.
But I tried many things and still I don't get the result.
I always tried using the fields "Content" and "Attachment" to search in.
How do I search a attachment using C#?
Is there a documentation about the elastic - C# - syntax?

my successful request:

GET /attachments/_search 
{
  "query": {
    "match": {
      "attachment.content": "Preisangebot"
    }
  }
}

My unsuccessful C# request:

            var searchResponse = client.Search<Document>(s => s
               .Query(q => q
                    .Match(m => m
                    .Field(f => f.Attachment.Content)
                    .Query("Preisangebot")
                    )
               )
            );

also unsuccessful:

            var searchRequest = new SearchRequest<Document>(Nest.Indices.All)
            {
                Query = new MatchQuery
                {
                    Field = Infer.Field<Document>(f => f.Content),
                    Query = "Preisangebot"
                }
            };
            var searchResponse2 = client.Search<Document>(searchRequest);

also unsuccessful:

            var searchResponse3 = client.Search<Document>(s => s
                .Index("attachments")
                .Query(q => q
                .Bool(b => b
                .Must(m => m
                .Match(mt => mt.Field(f => f.Content).Query("Preisangebot"))
            ))));

ingesting pdf files:

                        var base64File = Convert.ToBase64String(File.ReadAllBytes(path));
                        var indexResponse = client.Index(new Document
                        {
                            Id = i,
                            Path = path,
                            Content = base64File
                        }, i => i
                          .Pipeline("attachments")
                          .Refresh(Refresh.WaitFor)
                        );

Document class:

    public class Document
    {
        public int Id { get; set; }
        public string Path { get; set; }
        public string Content { get; set; }
        public Attachment Attachment { get; set; }
    }

I'm still very much interested in any ideas or answers.

Für alle die sich für das Thema interessieren, hier habe ich meine derzeitige Lösung beschrieben.
Bin aber offen für weitere Lösungen mit ElasticClient.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.