INTRODUCTION TO SEARCHINGby Bo Andersen - codingexplained.com
OUTLINE ➤ Relevancy & scoring ➤ Ways of searching ➤ Query string ➤ Query DSL ➤ Types of queries ➤ Leaf & compound ➤ Full text ➤ Term level ➤ Compound
RELEVANCY & SCORING ➤ To rank documents for a query, a score is calculated for each document that matches a query ➤ The higher the score, the more relevant the document is to the search query ➤ Queries in query context affect the scores of matching documents ➤ "How well does the document match?" ➤ Queries in filter context do not affect the scores of matching documents ➤ "Does the document match"
WAYS OF SEARCHING
QUERY STRING ➤ Search by sending search parameters through the REST request URI (as query parameters) ➤ Used for simple queries and ad-hoc queries on the command line ➤ Also supports advanced queries ➤ Example ➤ GET http://localhost:9200/ecommerce/product/_search?q=pasta
QUERY DSL ➤ Search by defining queries within the request body in JSON ➤ Supports more features than the query string approach ➤ Used for more advanced queries ➤ Often easier to read, as queries are defined in JSON GET http://localhost:9200/ecommerce/product/_search { "query": { "match": { "name": "pasta" } } }
TYPES OF QUERIES
LEAF & COMPOUND QUERIES ➤ Leaf ➤ Look for particular values in particular fields, for instance "pasta" in product names ➤ Can be used by themselves within a query, without being part of a compound query ➤ Can also be used within compound queries to construct more advanced queries ➤ Compound ➤ Wrap leaf clauses or even other compound query clauses ➤ Used to combine multiple queries in a logical fashion (usually with boolean logic) ➤ Can also be used to alter the behavior of queries
FULL TEXT ➤ Used for running full text queries on full text fields ➤ E.g. a product name or description ➤ Values are analyzed when adding documents or modifying values ➤ E.g. removing stop words, tokenizing and lowercasing ➤ Will apply each field's analyzer to the query string before executing
TERM LEVEL ➤ Used for exact matching of values ➤ Usually used for structured data like numbers and dates, rather than full text fields ➤ E.g. finding persons born between year 1980 and 2000 ➤ Search queries are not analyzed before executing
JOINING QUERIES ➤ Performing joins in a distributed system is expensive ➤ Elasticsearch offers two forms of joins that are designed to scale horizontally ➤ Nested query ➤ Documents may contains fields of type nested with arrays of objects ➤ Each object can be queried with the nested query as an independent document ➤ has_child and has_parent queries ➤ A parent-child relationship can exist between two document types within a single index ➤ The has_child query returns parent documents whose child documents match the query ➤ The has_parent query returns child documents whose parent document matches the query
GEO QUERIES ➤ Elasticsearch supports two types of geo fields ➤ geo_point (lat/lon pairs) ➤ geo_shape (points, lines, circles, polygons, etc.) ➤ Various geo queries use these fields to perform geographical searches ➤ E.g. finding points of interest near GPS coordinates
THANK YOU FOR WATCHING!

Introduction to Elasticsearch Searching

  • 1.
    INTRODUCTION TO SEARCHINGby BoAndersen - codingexplained.com
  • 2.
    OUTLINE ➤ Relevancy &scoring ➤ Ways of searching ➤ Query string ➤ Query DSL ➤ Types of queries ➤ Leaf & compound ➤ Full text ➤ Term level ➤ Compound
  • 3.
    RELEVANCY & SCORING ➤To rank documents for a query, a score is calculated for each document that matches a query ➤ The higher the score, the more relevant the document is to the search query ➤ Queries in query context affect the scores of matching documents ➤ "How well does the document match?" ➤ Queries in filter context do not affect the scores of matching documents ➤ "Does the document match"
  • 4.
  • 5.
    QUERY STRING ➤ Searchby sending search parameters through the REST request URI (as query parameters) ➤ Used for simple queries and ad-hoc queries on the command line ➤ Also supports advanced queries ➤ Example ➤ GET http://localhost:9200/ecommerce/product/_search?q=pasta
  • 6.
    QUERY DSL ➤ Searchby defining queries within the request body in JSON ➤ Supports more features than the query string approach ➤ Used for more advanced queries ➤ Often easier to read, as queries are defined in JSON GET http://localhost:9200/ecommerce/product/_search { "query": { "match": { "name": "pasta" } } }
  • 7.
  • 8.
    LEAF & COMPOUNDQUERIES ➤ Leaf ➤ Look for particular values in particular fields, for instance "pasta" in product names ➤ Can be used by themselves within a query, without being part of a compound query ➤ Can also be used within compound queries to construct more advanced queries ➤ Compound ➤ Wrap leaf clauses or even other compound query clauses ➤ Used to combine multiple queries in a logical fashion (usually with boolean logic) ➤ Can also be used to alter the behavior of queries
  • 9.
    FULL TEXT ➤ Usedfor running full text queries on full text fields ➤ E.g. a product name or description ➤ Values are analyzed when adding documents or modifying values ➤ E.g. removing stop words, tokenizing and lowercasing ➤ Will apply each field's analyzer to the query string before executing
  • 10.
    TERM LEVEL ➤ Usedfor exact matching of values ➤ Usually used for structured data like numbers and dates, rather than full text fields ➤ E.g. finding persons born between year 1980 and 2000 ➤ Search queries are not analyzed before executing
  • 11.
    JOINING QUERIES ➤ Performingjoins in a distributed system is expensive ➤ Elasticsearch offers two forms of joins that are designed to scale horizontally ➤ Nested query ➤ Documents may contains fields of type nested with arrays of objects ➤ Each object can be queried with the nested query as an independent document ➤ has_child and has_parent queries ➤ A parent-child relationship can exist between two document types within a single index ➤ The has_child query returns parent documents whose child documents match the query ➤ The has_parent query returns child documents whose parent document matches the query
  • 12.
    GEO QUERIES ➤ Elasticsearchsupports two types of geo fields ➤ geo_point (lat/lon pairs) ➤ geo_shape (points, lines, circles, polygons, etc.) ➤ Various geo queries use these fields to perform geographical searches ➤ E.g. finding points of interest near GPS coordinates
  • 13.