Elasticsearch-net: Add enable_position_increments as a Property on ITokenCountProperty

Created on 16 Dec 2020  路  7Comments  路  Source: elastic/elasticsearch-net

What I'm trying to achieve
I am trying to create a 'CreateIndexDescriptor' mapping descriptor using NEST Fluent API and I found that the enable_position_increments is not available on the TokenCountProperty class or on the TokenCountPropertyDescriptor (https://github.com/elastic/elasticsearch-net/blob/master/src/Nest/Mapping/Types/Specialized/TokenCount/TokenCountProperty.cs)

For my use case scenario, I need to store the token_count on a StopWords Analayzer with enable_position_increments set to false so that in stores the count after the Stopwords analyzer strips out the stop words. As per documentation here, https://www.elastic.co/guide/en/elasticsearch/reference/current/token-count.html , it defaults to true. So i need to explicitly set it to false for my use case.

This is how I set the "token_count" property (portion of the code on the fluent api)

.Properties(ps => ps.Text(
    ns => ns.Name(a => a.Value)
            .Analyzer("name_analyzer")
            .Fields(fs => fs
                .Text(ss => ss.Name("StopWords")
                    .Analyzer("stop_words_analyzer")
                    .Fields(f => f
                        .TokenCount(tc => tc
                                    .Name("length")
                                    .Analyzer("standard")))))

which generates this portion as a part of my mapping JSON

"StopWords": { 
    "type": "text",
    "fields": { 
        "length": { 
            "type": "token_count",
            "analyzer": "standard"
            }
        },
        "analyzer": "stop_words_analyzer"
}

I want to be able to add enable_position_increments to this JSON via the NEST Fluent API

"StopWords": { 
    "type": "text",
    "fields": { 
        "length": { 
            "type": "token_count",
            "analyzer": "standard",
           "enable_position_increments" : false
            }
        },
        "analyzer": "stop_words_analyzer"
}

The solution I would like
A bool property on ITokenCountProperty

[DataMember(Name ="enable_position_increments")]
bool? EnablePositionIncrements { get; set; }

and the Descriptor implementation for the same

Alternatives considered
I tried using the Custom method as suggested in guide post (https://www.elastic.co/guide/en/elasticsearch/client/net-api/current/extending-nest-types.html) but that Custom method seems to be available only on the PropertiesDescriptor class and not on the IPropertiesDescriptor interface... It's not available on the TokenCountPropertiesDescriptor class

Additional context
Is there any other workaround that I can use to set the enable_position_increments to false via NEST Client?

Feature

Most helpful comment

@rdasan You're welcome. I don't have exact dates for it yet, but it'll hopefully be sometime relatively soon in the new year.

All 7 comments

Also I have the fix for this feature in a local branch with updated Unit Tests... I don't seem to have permissions to push up my branch so that I can submit a PR for it. I did sign the "Individual Contributor License Agreement" and submit the docusign document

Also I have the fix for this feature in a local branch with updated Unit Tests... I don't seem to have permissions to push up my branch so that I can submit a PR for it.

In order to submit a PR, you'll need to

  1. fork the repository to an account under your control e.g. https://github.com/rdasan,
  2. configure https://github.com/elastic/elasticsearch-net as a remote repository (usually named upstream) of the fork
  3. create a branch on the fork with the fix
  4. open a PR against upstream,

Take a look at https://docs.github.com/en/free-pro-team@latest/github/collaborating-with-issues-and-pull-requests/creating-a-pull-request-from-a-fork for more details

@russcam Thanks for the tip... Have submitted the PR : https://github.com/elastic/elasticsearch-net/pull/5188

Have opened a PR against the 7.x branch as well. Since I'm using the latest 7.10.1 NEST nuget package. I'm assuming that's the correct branch for the PR merge? #5189

I've merged #5188, thank yo @rdasan. I'll backport this and it'll be included in the 7.11 release.

@stevejgordon / @russcam Thanks for the quick review, approval and merge of the PR. Much appreciated.
what would be the tentative date for 7.11 release?

@rdasan You're welcome. I don't have exact dates for it yet, but it'll hopefully be sometime relatively soon in the new year.

Was this page helpful?
0 / 5 - 0 ratings