# Elasticsearch using escape character with shingle token filter

**URL:** <https://discuss.elastic.co/t/elasticsearch-using-escape-character-with-shingle-token-filter/60264>\
**Category:** Elasticsearch\
**Created:** [September 12, 2016, 8:36am UTC](https://discuss.elastic.co/t/elasticsearch-using-escape-character-with-shingle-token-filter/60264 "2016-09-12T08:36:07Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![stormcloak](https://avatars.discourse-cdn.com/v4/letter/s/e274bd/32.png) [@stormcloak](https://discuss.elastic.co/u/stormcloak)\
**Post date:** [September 12, 2016, 8:36am UTC](https://discuss.elastic.co/t/elasticsearch-using-escape-character-with-shingle-token-filter/60264/1 "2016-09-12T08:36:07Z")

</div>

I have two documents on my index. **I want to play football** and **I want to play basketball**

With use **shingle token filter,** i want to analyze this documents like that

**I**

**I want**

**I want to**

**Want**

**Want to**

**Want to play etc.**

And I want to search with querystring something like this **play\ foot** \*.

I expected one record with this query but after execution, i had two records. Because Elasticsearch executed this querystring as **play OR foot** \*. Escape character is not working in this situation.

I am using NEST library in .Net Framework. And my code is

```
var node = new Uri("http://localhost:9200");
            const string indexName = "exampleforshingleanalyzer";
            var settings = new ConnectionSettings(
                node,
                defaultIndex: indexName
            );
            Console.WriteLine("Program Starting...");
            var client = new ElasticClient(settings);
            client.DeleteIndex(t => t.AllIndices());
            var analyzerSettings = new CustomAnalyzer();
            analyzerSettings.Filter = new List<string>();
            analyzerSettings.Filter.Add("shingle_token_filter");
            analyzerSettings.Tokenizer = "standard";
            client.CreateIndex(indexName, t => 
                t.Analysis(a =>
                    a.TokenFilters(token => token.Add("shingle_token_filter",new ShingleTokenFilter
                    {
                        MaxShingleSize = 3,
                        MinShingleSize = 2,
                        OutputUnigrams = true,
                        TokenSeparator = "-"
                    }))
                    .Analyzers(an => an.Add("shingle_analyzer", analyzerSettings)))
                .NumberOfReplicas(1)
                .NumberOfShards(1)
                .AddMapping<FtsResult>(c => c.MapFromAttributes()
                .IgnoreConflicts()
                .Type("ftsresult")
                .Index(indexName)
                .Properties(p => p
                .String(s => s.Name(f => f.AgentText).Analyzer("shingle_analyzer").SearchAnalyzer("shingle_analyzer").IndexAnalyzer("shingle_analyzer"))
                .String(s => s.Name(f => f.CustomerText).Analyzer("shingle_analyzer").SearchAnalyzer("shingle_analyzer").IndexAnalyzer("shingle_analyzer"))
                )

            ));

            var sample = new FtsResult
            {
                Id = 1,
                AgentText = "i want to play football"
            };
            var sample2 = new FtsResult
            {
                Id = 2,
                AgentText = "i want to play basketball"
            };
            client.Index(sample, t => t.Index(indexName).Type("ftsresult"));
            client.Index(sample2, t => t.Index(indexName).Type("ftsresult"));
            client.Refresh(r => r.Index(indexName));

            //Getting two records
            var result = client.Search<FtsResult>(s => s
            .Index(indexName)
            .Query(q => q.QueryString(qs => qs.Query("play\\ foot*").AnalyzeWildcard()))
            );

            //Getting two records
            var result2 = client.Search<FtsResult>(s => s
            .Index(indexName)
            .Query(q => q.QueryString(qs => qs.Query(@"play\ foot*").AnalyzeWildcard()))
            );

        //Getting nothing
        var result3 = client.Search<FtsResult>(s => s
            .Index(indexName)
            .Query(q => q.QueryString(qs => qs.Query("\"play foot*\"").AnalyzeWildcard()))
            );

        Console.ReadLine();

```

And my FtsResult object is

```
[Serializable]
public class FtsResult
{
    public long Id { get; set; }

    [ElasticProperty(Index = FieldIndexOption.No)]
    public int Rank { get; set; }

    [ElasticProperty(Index = FieldIndexOption.Analyzed)]
    public string AgentText { get; set; }

    [ElasticProperty(Index = FieldIndexOption.No)]
    public string AgentTextTimes { get; set; }

    [ElasticProperty(Index = FieldIndexOption.Analyzed)]
    public string CustomerText { get; set; }

    [ElasticProperty(Index = FieldIndexOption.No)]
    public string CustomerTextTimes { get; set; }

    [ElasticProperty(Index = FieldIndexOption.NotAnalyzed)]
    public string EsIndiceName { get; set; }
}

```

I writed results with comments on result objects. I **expect only one record** with this query. Could anyone point me in the right direction ?

---

<div class="post-metadata">

**Author:** ![javanna](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/javanna/32/4698_2.png) [@javanna](https://discuss.elastic.co/u/javanna)\
**Post date:** [September 12, 2016, 12:40pm UTC](https://discuss.elastic.co/t/elasticsearch-using-escape-character-with-shingle-token-filter/60264/2 "2016-09-12T12:40:50Z")

</div>

Can you post a recreation of your problem using curl requests please?

---

<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:21pm UTC](https://discuss.elastic.co/t/elasticsearch-using-escape-character-with-shingle-token-filter/60264/3 "2017-07-05T22:21:06Z")

</div>


