# NEST API to configure built in analyzers

**URL:** <https://discuss.elastic.co/t/nest-api-to-configure-built-in-analyzers/64542>\
**Category:** Elasticsearch\
**Created:** [November 1, 2016, 10:52am UTC](https://discuss.elastic.co/t/nest-api-to-configure-built-in-analyzers/64542 "2016-11-01T10:52:45Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![paul2](https://avatars.discourse-cdn.com/v4/letter/p/df705f/32.png) [@paul2](https://discuss.elastic.co/u/paul2)\
**Post date:** [November 1, 2016, 10:52am UTC](https://discuss.elastic.co/t/nest-api-to-configure-built-in-analyzers/64542/1 "2016-11-01T10:52:45Z")

</div>

Hi,

I'm trying to figure out how to set one of my fields to use the Pattern Analyzer with "\W|\_" Basically the 'fullAddress' field could include an underscore within the postcode, eg WC1V\_6hh.

I want to do a wildcard search eg. WC1V\*

It looks like I should use the 'Simple Analyzer' which would break up the underscore and use lowercase. However, I'm sure I've seen that if a number was part of the underscore term then the simple / standard analysers wouldn't break it up. So in that case I would use the Pattern Analyser with the regex pattern \W|\_

If I was to use the Simple Analyzer then I can decorate the poco property like this?

> [String(Name = "FULLADDRESS", Analyzer = "Simple")]  
> public string FullAddress { get; set; }

About to test this but how do I decorate using the pattern analyzer?

---

<div class="post-metadata">

**Author:** ![gmarz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gmarz/32/22178_2.png) [@gmarz](https://discuss.elastic.co/u/gmarz)\
**Post date:** [November 1, 2016, 3:04pm UTC](https://discuss.elastic.co/t/nest-api-to-configure-built-in-analyzers/64542/2 "2016-11-01T15:04:58Z")

</div>

Yes, you can use either attributes or the fluent API to assign an analyzer to a field. Just FYI though, you need to create the index with the analyzer configured first.

For instance, if you have the following POCO:

```auto
public class MyDoc
{
    [String(Name="mField", Analyzer = "my_pattern_analyzer")]
    public string MyField { get; set; }
}

```

Then you'd create your index with `my_pattern_analyzer`, and use `AutoMap()` to pick up the `String` attribute set on the `MyField` property:

```auto
var response = client.CreateIndex("myindex", c => c
	.Settings(s => s
		.Analysis(a => a
			.Analyzers(az => az
				.Pattern("my_pattern_analyzer", p => p
					.Pattern("\\W|_")
					.Lowercase()
				)
			)
		)
	)
	.Mappings(ms => ms
		.Map<MyDoc>(m => m.AutoMap())
	)
);

```

You can also use just the fluent API, which is actually preferred since it can handle more complex mappings that can't be expressed using attributes alone.

```auto
public class MyDoc
{
    public string MyField { get; set; }
}

```

```auto
var response = client.CreateIndex("myindex", c => c
	.Settings(s => s
		.Analysis(a => a
			.Analyzers(az => az
				.Pattern("my_pattern_analyzer", p => p
					.Pattern("\\W|_")
					.Lowercase()
				)
			)
		)
	)
	.Mappings(ms => ms
		.Map<MyDoc>(m => m
			.AutoMap()
			.Properties(ps => ps
				.String(str => str
					.Name(p => p.MyField)
					.Analyzer("my_pattern_analyzer")
				)
			)
		)
	)
);

```

You may find the [docs on auto mapping](https://www.elastic.co/guide/en/elasticsearch/client/net-api/2.x/auto-map.html) useful. Hope that helps!

---

<div class="post-metadata">

**Author:** ![paul2](https://avatars.discourse-cdn.com/v4/letter/p/df705f/32.png) [@paul2](https://discuss.elastic.co/u/paul2)\
**Post date:** [November 1, 2016, 3:34pm UTC](https://discuss.elastic.co/t/nest-api-to-configure-built-in-analyzers/64542/3 "2016-11-01T15:34:27Z")

</div>

That was the perfect answer. I was close but got a little lost. I wish there were more examples in the documentation

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 5, 2017, 10:07pm UTC](https://discuss.elastic.co/t/nest-api-to-configure-built-in-analyzers/64542/4 "2017-07-05T22:07:50Z")

</div>


