_search

  • -

_search

Category : latest version

Any search usecases (like Full text search, Geo search, Terms search) are the biggest ElasticWarehouse features. Restpoint _search allows you to search for files by its contents in more advance way than _searchall.

Parameter Requirement Type Description
query mandatory string Search query phase. Query phase is being used to build multi match query. For simplest search approach please refer to _ewsearchall restpoint described in the previous point.
options.from optional int As default, search request returns 10 results. Parameter defines the offset from the first result you want to fetch. Increase “from” value to iterate through all results.
options.size optional int As default, search request returns 10 results. The size parameter allows you to configure the maximum amount of documents to be returned.
options.highlight optional boolean Default value is false. When set to “true” ElasticWarehouse returns context with highlighted query phase.
options.fragmentSize optional int Default value is 300. Attribute to define context size for highlighting. Used only when highlight="true".
options.pretag optional string Tag to mark begin of highlighted context. Used only when highlight="true".
options.posttag optional string Tag to mark end of highlighted context. Used only when highlight="true".
options.showrequest optional boolean When set to “true” ElasticWarehouse node prints converted JSON request on standard output. Converted JSON request can be executed directly on ElasticSearch cluster. It’s useful when you plan to build your own ElasticWarehouse client connected directly to the ElasticSearch cluster.
options.scanembedded optional boolean An attribute to include embedded files in resultset. This is useful when file you are looking for has been added i.e. to some WORD or PDF document.
sort.field optional string Field to sort by. To sort by relevancy, use custom field: "score". To sort by nearest geographical location, use: "location"
sort.direction optional enum:asc,desc Defines sorting order

Full text search and Terms search

Find all files which contain phase *geo* in /home/user folder

curl -XPOST "http://localhost:10200/_ewsearch" -d '{
   "query": {
      "folder": "/home/user",
      "all": "*geo*"
   },
   "options": {
      "scanembedded": "true",
      "showrequest": "true",
      "size": 20,
      "from": 2,
      "highlight": "true",
      "pretag": "[b][i]",
      "posttag": "[/i][/b]"
   },
   "sort": {
      "field": "fileuploaddate",
      "direction": "desc"
   }
}'

Find all files with width equal to 64 pixels and filesize between 24KB and 50KB. In this example we also use scanembedded=true to scan extracted embedded files. This is useful when you suspect file you are looking for has been added i.e. to some WORD or PDF files. Sort results by upload timestamp.

curl -XPOST "http://localhost:10200/_ewsearch" -d '{
   "query": {
      "imagewidth": 64,
      "filesize": {
         "from": 24000,
         "to": 50000
      }
   },
   "options": {
      "scanembedded": "true",
      "size": 20,
      "from": 0
   },
   "sort": {
      "field": "fileuploaddate",
      "direction": "desc"
   }
}'

Final all files with *brand* text in the filename and height between 200 and 500 pixels. Sort results by relevancy.

curl -XPOST "http://localhost:10200/_ewsearch" -d '{
   "query": {
      "filename": "*test*",
      "imageheight": {
         "from": 200,
         "to": 500
      }
   },
   "sort": {
      "field": "score",
      "direction": "desc"
   }
}'

Find all files uploaded between “2015-07-20 13:10:30″ and “2015-07-28 13:10:33″

curl -XPOST "http://localhost:10200/_ewsearch" -d '{
   "query": {
      "fileuploaddate": {
         "from": "2015-07-20 13:10:30",
         "to": "2015-07-28 13:10:33"
      }
   },
   "sort": {
      "field": "fileuploaddate",
      "direction": "desc"
   }
}'

Find all images made by Canon 40D

curl -XPOST "http://localhost:10200/_ewsearch" -d '{
   "query": {
      "filename": "jpg",
      "filemeta.metavaluetext": "canon 40D"
   },
   "options": {
      "scanembedded": "true"
   },
   "sort": {
      "field": "score",
      "direction": "desc"
   }
}'

Find all images modified by Photoshop

curl -XPOST "http://localhost:10200/_ewsearch" -d '{
   "query": {
      "filename": "jpg",
      "filemeta.metavaluetext": "Photoshop"
   },
   "options": {
      "scanembedded": "true"
   },
   "sort": {
      "field": "score",
      "direction": "desc"
   }
}'

Search with subfolders included can be achieved by adding * to the folder name:

curl -XPOST "http://localhost:10200/_ewsearch" -d '{
   "query": {
      "folder": "/home/*",
      "all": "*geo*"
   },
   "sort": {
      "field": "fileuploaddate",
      "direction": "desc"
   }
}'

Geo location search

Geo Location Search is one of the best search technology features ever. ElasticWarehouse’s ability to combine geo and search gives possibilities to use such feature in many ways. For example, you may want to find all pictures made in some geographical region, return documents from geographically closest copy or visualize places where uploads are most often.

Distance search:

curl -XPOST "http://localhost:10200/_ewsearch" -d '{
   "query": {
      "filenamena": "*Commented_xnviewmp026*",
        "location" : { "distance" : "1m", "lat" : 56.0125, "lon" : 14.462778 }

   },
   "options": {
      "scanembedded": "true",
      "showrequest" : "true"
   },
   "sort": {
      "field": "location",
      "direction": "desc"
   }
}'

Bounding box search. Box Geo search expects exactly two points to define ‘top left’ and ‘bottom right’ box corners (in following order: first array element => ‘top left’, second array element => ‘bottom right’)

curl -XPOST "http://localhost:10200/_ewsearch" -d '{
   "query": {
        "location" : { "box" : [{"lat" : 55, "lon" : -55}, {"lat" : 10, "lon" : 0}] }

   },
   "options": {
      "scanembedded": "true",
      "showrequest" : "true"
   },
   "sort": {
      "field": "score",
      "direction": "desc"
   }
}'

Polygon search:

curl -XPOST "http://localhost:10200/_ewsearch" -d '{
   "query": {
        "location" : { "polygon" : [
                {"lon" : -5.2, "lat" : 52}, 
                {"lon" : 14.5, "lat" : 57}, 
                {"lon" : 14.5, "lat" : 0}, 
                {"lon" : -5.2, "lat" : 0}] }
   },
   "options": {
      "scanembedded": "true",
      "showrequest" : "true"
   },
   "sort": {
      "field": "score",
      "direction": "desc"
   }
}'

Need more?

If ElasticWarehouse API is not enough for you, then you may always use ElasticSearch API. ElasticWarehouse accepts all typical ElasticSearch requests, like HTTP REST API calls, Transport and Node clients connections and all other possible requests available in underlying ElasticSearch version. Read more here about it.

_searchall
_ewsummary