Jason
Jason

Reputation: 23

NEST ElasticSearch.NET Escape Special Characters

I have been experimenting with the use of the NEST client for Elastic Search, but seem to have hit a barrier when filtering on a term which contains special/reserved characters such as '/'

Below is a JSON representation of my model..

"categories": {
    "count": 1,
    "default": "root/Hello/World/Category",
}

When submitting a search for any part of the categories.default field, for example "root" or "Hello" i will receive a match, however when searching for the full string, or any string containing '/' no matches are found.

I understand from some research, that this is because reserved characters are replaced during the indexing/tokenisation process - however I have yet been unable to determine a way around the issue.

Any help would be greatly appreciated

Example search query added below

var result = ElasticSearchClient.Search<Schema.Product>(s => s
    .From(0)
    .Size(10)
    .MatchAll()
    .FilterRaw("{ \"term\": { \"categories.default\": \"root/Hello\" } }")
);

Upvotes: 1

Views: 3084

Answers (1)

Bantu Tech
Bantu Tech

Reputation: 234

You will need to setup a multifield as the dash is causing the terms to be split. I have found an answer to a similar question which answers yours: https://stackoverflow.com/a/28859145/4134821

Upvotes: 1

Related Questions