1

I am running an app basically creating a URL shortener and when I setup the "shorurl" which is upper and lower case I cannot get a Query or a Filter to find it. However for other fields that are more simple it works just fine. I tried doing lower case on it not sure really how to match.

Here is the field definition:

       [ElasticProperty(Name = "shorturl", IncludeInAll = true)]
        public string ShortUrl { get; set; }

Here is an example:

        string url = "http://test.com/JjdWtPoV";

        FilterContainer filter = new FilterContainer();
        filter = Filter<Data>.Term("shorturl", url);

        var results = this.Client.Search<Data>(s => s
            .Filter(filter)
        );

        QueryContainer q = new QueryContainer();
        q = Query<Data>.Term("shorturl", url);

        results = this.Client.Search<Data>(s => s
            .Query(q)
        );

        results = this.Client.Search<Data>(s => s
            .Query(f => f.Term(p=> p.ShortUrl, url))
        );

I should note the following is what versions I'm using:

        <?xml version="1.0" encoding="utf-8"?>
        <packages>
          <package id="Elasticsearch.Net" version="1.3.1" targetFramework="net45" />
          <package id="NEST" version="1.3.1" targetFramework="net45" />
          <package id="Newtonsoft.Json" version="6.0.1" targetFramework="net45" />
        </packages>

FOUND THE ANSWER Need to ensure a string has "NOT ANALYZED" set

        [ElasticProperty(Name = "shorturl", IncludeInAll = true,                          
                    Index=FieldIndexOption.NotAnalyzed)]
        public string ShortUrl { get; set; }

1 Answer 1

2
   [ElasticProperty(Name = "shorturl", IncludeInAll = true,                          
                Index=FieldIndexOption.NotAnalyzed)]
    public string ShortUrl { get; set; }
Sign up to request clarification or add additional context in comments.

2 Comments

Perhaps you could explain what is going on in your code, to help others. How does this work exactly?
@Mohamadshiralizadeh string fields by default will be analyzed using the standard analyzer which will, amongst other things, lowercase tokens generated from the input when storing them in the inverted index. A terms query/filter does not analyze the query input, so there's a mismatch between the query input and the indexed input in terms of analsis (not analyzed vs. analyzed, respectively). If you want to do term(s) queries on a field, might also want to store as not_analyzed, either the field directly (as in this case), or map it as a multi_field with a not_analyzed sub-field

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.