Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

problem while working with elasticsearch-mapper-attachments plugin #972

Closed
jacyuan opened this issue Oct 2, 2014 · 4 comments
Closed

problem while working with elasticsearch-mapper-attachments plugin #972

jacyuan opened this issue Oct 2, 2014 · 4 comments

Comments

@jacyuan
Copy link

jacyuan commented Oct 2, 2014

Hello,
I got a little trouble while trying to use Nest with elasticsearch-mapper-attachments plugin.
In fact, the mapping from attributs defined in a class doesn't seem work well.

The detail is here listed in stack overflow
http://stackoverflow.com/questions/25917386/client-net-nest-with-attachment-highlight-feature

Appreciate if you can give me some advice on it.

Thank you very much

Yuan

@gmarz
Copy link
Contributor

gmarz commented Oct 3, 2014

Hey @jacyuan

I'm assuming you're trying to apply the term vector options to the attachment metadata field mappings (author, title, etc..), and not the attachment field itself.

You can't use the ElasticProperty attribute for complex mappings like this; it isn't flexible enough. The attribute based mapping is really only for simple/core mappings, and should be avoided really as we're thinking of deprecating it.

Instead, try using the fluent API:

  client.Map<YourType>(m => m
    .Properties(ps => ps
      .Attachment(a => a
        .Name(o => o.YourAttachmentField)
        .TitleField(t => t.Name("title").TermVector(TermVectorOption.WithPositionsOffsets))
      )
    )
  );

Or at the time you're creating the index:

  client.CreateIndex("your-index-name", c => c.AddMapping<YourType>(m => m
      .Properties(ps => ps
        .Attachment(a => a
          .Name(o => o.YourAttachmentField)
          .TitleField(t => t.Name("title").TermVector(TermVectorOption.WithPositionsOffsets))
        )
      )
    )
  );

@jacyuan
Copy link
Author

jacyuan commented Oct 6, 2014

Hello @gmarz,

Thank you very much for ur help. This solution works well.

While waiting for solutions, we also tried to supply mapping for a type, explicitly by doing a http put request with a json mapping file.

As u v mentioned, u may deprecate the use of attributes in later version of nest (since this solution works currently only for attributes with simple data type).
We see the facility of using attributes annotating directly in a class definition, and then using mapfromattribute function to generate the mapping automatically.
Without attributes annotation, does it mean, each time when we need to give an explicit mapping for a type, we will need to build (manually) this mapping, either by using a mapping json file or by using the fluent API?

Thanks again

@gmarz
Copy link
Contributor

gmarz commented Oct 6, 2014

@jacyuan

Great, glad that worked!

It's hard to say now without giving it more thought, but I would say no- if we were to deprecate attributes, we would have to do so in a way that would still allow mapping properties of a class automatically so that you wouldn't have to explicitly setup each mapping manually.

@gmarz gmarz closed this as completed Oct 6, 2014
@nasreekar
Copy link

@jacyuan Hi Jacyuan... I am working on something similar to yours.. I have a folder in which i have some documents(pdf,.doc, .docx) and i have to read all of the documents in the folder and index them to ES server.(using NEST) I searched a lot on google for some possible solution and couldnt find any. Can you please help me in solving this. (like how do i start, what should be the flow be like or any sample code if you have) TIA :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants