简体   繁体   中英

Elasticsearch.net NEST cannot filter on URL

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; }
   [ElasticProperty(Name = "shorturl", IncludeInAll = true,                          
                Index=FieldIndexOption.NotAnalyzed)]
    public string ShortUrl { get; set; }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM