Giter Club home page Giter Club logo

elasticsearch's Introduction

Elasticsearch .NET Client

.NET client using (NEST API) for simple full text search with sample queries. Java client (Java High Level REST Client) is in "java" branch.

Run the .NET application

  1. Download Elasticsearch and follow instructions from https://www.elastic.co/downloads/elasticsearch in order to run bin\elasticsearch.bat on Windows.
  2. Run the application on Visual Studio.

Update for .NET application

  • Queries are in ElasticSearchASPApplication.Services namespace. Current implementation only calls SimpleSearch function.
  • Search results are not shown in ASP.NET view. Run/Debug test cases instead.

Sample Queries

Searching all products

GET /company/product/_search/

Using query DSL for more usefull search

In order to make a more useful search request, we also need to supply a request body with a query.

POST /company/product/_search/
{
    "query": {
        "query_string": {
          "query": "Huawei", 
        }
      }
}

Fine tuning query string queries

Retrieve documents with the name of “Huawei”

POST /company/product/_search/
{
    "query": {
        "query_string": {
          "query": "Huawei", 
          "fields": [
            "name"
         ]
        }
      }
}

Searching for multiple products

POST /company/product/_search/
{
    "query": {
        "query_string": {
          "query": "Huawei iPhone6s",
          }
      }
}

Filtering

Filter for specific value:
POST /company/product/_search/
{
   "query": {
      "bool": {
         "must": {
            "match": {
               "name": "Samsung"
            }
         },
         "filter": {
            "term": {
               "price": 2900
            }
         }
      }
   }
}

Filter with a range:
POST /company/product/_search/
{
   "query": {
      "bool": {
         "must": {
            "match": {
               "name": "Samsung"
            }
         },
         "filter": [
            {
               "range": {
                  "price": {
                     "gte": 1000,
                     "lte": 4000
                  }
               }
            }
         ]
      }
   }
}

Sorting

Sort all products
POST /company/product/_search/
{
   "query": {
     "match_all": {}
   },
   "sort": {
      "price": "asc"
   }
}

Sort product with a name "Samsung"

POST /company/product/_search/
{
   "query": {
      "query_string": {
         "query": "Samsung"
      }
   },
   "sort": {
      "price": "asc"
   }
}

Pagination

ElasticSearch returns the first ten hits by default. You can change it via size parameter.

POST /company/product/_search/
{
   "query": {
     "match_all": {}
   },
   "sort": {
      "price": "asc"
   },
   "size": 12
}

Retrieving only parts of documents

Add _source property to the query. Following query retrieves only “name” of all products. It is also possible to retrieve multiple fields as well using "_source": ["property1", "property2"]

Query:
POST /company/product/_search/
{
  "_source": "name"
}

Result:
{
    "_index": "company",
    "_type": "product",
    "_id": "AV57gFjUQ8Qv2Iw4gRgt",
    "_score": 1,
    "_source": {
      "name": "iPhone7"
    }
}

elasticsearch's People

Contributors

barrida avatar

Watchers

James Cloos avatar Tomny avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.