1

I am trying to do indexing of certain fields from POCO class and decorating some of the properties as "Ignore = true" and those fields should not be indexed but should be stored. I want those fields to appear in the search result but should not be index.

I am trying to do the mapping of few fields which should be indexed and ignoring all the other fields that have "Ignore = true" as the decorator provided by Nest Library.

Here is the example of the of the POCO class.

[PropertyName("doi")]
public string Doi { get; set; }

[PropertyName("displayName")]
public string DisplayName { get; set; }

[PropertyName("itemType")]
public string ItemType { get; set; }

[PropertyName("fileReference")]
public string FileReference { get; set; }

[PropertyName("textFirstPage", Ignore = true)]
public string TextFirstPage { get; set; }

[PropertyName("textLastPage", Ignore = true)]
public string TextLastPage { get; set; }

[PropertyName("citationTitle", Ignore = true)]
public string CitationTitle { get; set; }

[PropertyName("translatedPublicationTitle", Ignore = true)]
public string TranslatedPublicationTitle { get; set; }

[PropertyName("alternatePublicationTitle", Ignore = true)]
public string AlternatePublicationTitle { get; set; }

[PropertyName("publicationSubTitle", Ignore = true)]
public string PublicationSubTitle { get; set; }

But all the fields that have been mentioned in the POCO class is appearing in the Mapping when I try to see the Mapping of the Index.

{
    "cweeindex" : {
        "mapping": {
            "properties" : {
                "doi": {
                    "type": "text",
                    "fields": {
                        "keyword": {
                            "type": "keyword",
                            "ignore_above": 256
                        }
                    }
                },
                "displayName": {
                    "type": "text",
                    "fields": {
                        "keyword": {
                            "type": "keyword",
                            "ignore_above": 256
                        }
                    }
                },
                "fileReference": {
                    "type": "text",
                    "fields": {
                        "keyword": {
                            "type": "keyword",
                            "ignore_above": 256
                        }
                    }
                },
                "itemType": {
                    "type": "text",
                    "fields": {
                        "keyword": {
                            "type": "keyword",
                            "ignore_above": 256
                        }
                    }
                },
                 "citationTitle": {
                    "type": "boolean"
                },
                "publicationSubTitle": {
                    "type": "text",
                    "fields": {
                        "keyword": {
                            "type": "keyword",
                            "ignore_above": 256
                        }
                    }
                },
                "textFirstPage": {
                    "type": "text",
                    "fields": {
                        "keyword": {
                            "type": "keyword",
                            "ignore_above": 256
                        }
                    }
                },
                "textLastPage": {
                    "type": "text",
                    "fields": {
                        "keyword": {
                            "type": "keyword",
                            "ignore_above": 256
                        }
                    }
                },
                "translatedPublicationSubTitle": {
                    "type": "text",
                    "fields": {
                        "keyword": {
                            "type": "keyword",
                            "ignore_above": 256
                        }
                    }
                },
                "translatedPublicationTitle": {
                    "type": "text",
                    "fields": {
                        "keyword": {
                            "type": "keyword",
                            "ignore_above": 256
                        }
                    }
                },
            }   
        }
    }
}

UPDATE!! The Nest code for Mapping is below

var createIndexResponse = _connectionToEs.EsClient().Indices.Create("cweeindex", c => c
                                                    .Map<EsStandardContract>(m => m.AutoMap())
                                                );

Please, let me what am I doing wrong!! Thanks in Advance.

2
  • Could you share NEST code which is creating index mapping? Commented Sep 29, 2019 at 18:59
  • Sorry for the delayed reply @Rob I have updated the description Commented Sep 30, 2019 at 6:40

2 Answers 2

1

This looks like a regression that has come about with the serialization changes from 6.x to 7.x. I've opened an issue to address.

For now, you can use Nest.IgnoreAttribute. For example

[PropertyName("doi")]
public string Doi { get; set; }

[PropertyName("displayName")]
public string DisplayName { get; set; }

[PropertyName("itemType")]
public string ItemType { get; set; }

[PropertyName("fileReference")]
public string FileReference { get; set; }

[Ignore]
public string TextFirstPage { get; set; }

[Ignore]
public string TextLastPage { get; set; }

[Ignore]
public string CitationTitle { get; set; }

[Ignore]
public string TranslatedPublicationTitle { get; set; }

[Ignore]
public string AlternatePublicationTitle { get; set; }

[Ignore]
public string PublicationSubTitle { get; set; }
Sign up to request clarification or add additional context in comments.

4 Comments

Thanks @Russ for addressing this issue.
Hi @Russ, with adding [Ignore] on properties, those properties are not coming in the mapping. But these fields are being ignored while we do indexing. As I have mentioned in the question, I want to store the data in the properties but don't want to index those and should not appear in the mapping. Can you suggest some other way.
I’m not sure what you mean by “I want to store the data in the properties but don’t want to index those”. Can you clarify?
I mean only those properties in the "Mapping" should be searchable and filtered and thus be indexed, but want to keep other properties, which are not in the Mapping, data in the document also. The [Ignore] decorator doesn't add these fields in the Mapping, also these properties are getting ignored while indexing the POCO class containing all the fields.
0

Thanks for all your help.

Since [Ignore] decorator was not allowing the fields to be added in the Mapping, it was also ignoring the properties while indexing. What I wanted was to have a Mapping with certain fields but the document created while indexing should contain some other fields that had value, which was to be used while getting results (more like projection fields) in the Output. I didn't wanted these fields to be included dynamically so I created a Mapping Class Object which had all the Properties to be included in the mapping of the index and was set dynamic=false.

Then while indexing I am using another class object which had all the properties which were included in the mapping and also some other properties. These other properties will be used while getting results/output but I didn't wanted these to be searchable or filterable(meaning, didn't wanted to index).

Here's a Mapping class

 public class EsMappingContract
{
    [PropertyName("doi")]
    public string Doi { get; set; }

    [PropertyName("displayName")]
    public string DisplayName { get; set; }

    [PropertyName("itemType")]
    public string ItemType { get; set; }

    [PropertyName("fileReference")]
    public string FileReference { get; set; }
}

Here's the Indexing Class

public class EsIndexingContract
{
    [PropertyName("doi")]
    public string Doi { get; set; }

    [PropertyName("displayName")]
    public string DisplayName { get; set; }

    [PropertyName("itemType")]
    public string ItemType { get; set; }

    [PropertyName("fileReference")]
    public string FileReference { get; set; }

    [PropertyName("citationTitle", Ignore = true)]
    public string CitationTitle { get; set; }

    [PropertyName("translatedPublicationTitle", Ignore = true)]
    public string TranslatedPublicationTitle { get; set; }

    [PropertyName("alternatePublicationTitle", Ignore = true)]
    public string AlternatePublicationTitle { get; set; }

    [PropertyName("publicationSubTitle", Ignore = true)]
    public string PublicationSubTitle { get; set; }
}

I didn't knew that [Ignore] will ignore the properties while indexing also and thus I had to go for this approach. I would have liked some other decorator that would have indicated ES to ignore while creating Mapping but should not be ignored on indexing, if the properties had value.

Thanks again for the help!! Hope this helps somebody in future.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.