엘라스틱서치 이해하기 20160613

252
엘엘엘엘엘엘 엘엘엘엘 Moon Yong Joon

Upload: yong-joon-moon

Post on 05-Apr-2017

1.277 views

Category:

Software


7 download

TRANSCRIPT

PowerPoint

Moon Yong Joon

Moon Yong Joon

JSON

JSON JSON :

JSON JSON , , { "email": "[email protected]", "first_name": "John", "last_name": "Smith", "info": { "bio": "Eco-warrior and defender of the weak", "age": 25, "interests": [ "dolphins", "whales" ] }, "join_date": "2014/05/01"}

index, type, document, field FieldFieldDocumenttypetypeindexindexFieldFieldDocumentFieldFieldDocumentFieldFieldDocumentFieldFieldDocumenttype

RDB RDBElasticsearchDATABASEINDEXTABLETYPEROWDOCUMENTCOLUMNFIELDSCHEMAMAPPING

: elasticsearch-head

Curl

elasticsearch HTTP , , , curl -X{} http://host:port/{}{}/{ id} -d "{}" MethodPUT id POST id GET id DELETE HEAD

( postman )

http url raw json

Get json post

Windows

Window Command \

\

Window : windows \

Window : Command \ # C:\>curl -XPUT http://localhost:9200/books/book/1 -d "{ \"title\": \"Elasticsearch Guide\", \"author\": \"kim\", \"date\" : \"2014-05-01\", \"pages\" : 250 }"

#{"_index":"books","_type":"book","_id":"1","_version":1,"_shards":{"total":2,"successful":1,"failed":0},"created":true}

Window :

# C:\>curl -XGET http://localhost:9200/books/book/1?pretty=true{ "_index" : "books", "_type" : "book", "_id" : "1", "_version" : 1, "found" : true, "_source" : { "title" : "Elasticsearch Guide", "author" : "kim", "date" : "2014-05-01", "pages" : 250 }}

Field

Moon Yong Joon

Field

Field , (Mapping) :

Field : Mapping Document Type mapping doument { "name": "dahlmoon"}{ "properties": { "name": { "type": "string" } }}Mappingdocument

String

String : index/type Index type full_name status full_name full text(analyzed) status keyword(not_analyzed)

Status keyword

String : Index type full_name status

String : analyze _analyze api

String String mapping store_source index analyzed : , not_analyzed : , No : boost null_value analyzer , index analyzed Index_analyzer search_analyzer . include_in_all_all ignore_above not_analyzed

Numeric

Numeric type integer/float PUT my_index{ "mappings": { "my_type": { "properties": { "number_of_bytes": { "type": "integer" }, "time_in_seconds": { "type": "float" } } } }}longA signed 64-bit integer with a minimum value of-263and a maximum value of263-1.integerA signed 32-bit integer with a minimum value of-231and a maximum value of231-1.shortA signed 16-bit integer with a minimum value of-32,768and a maximum value of32,767.byteA signed 8-bit integer with a minimum value of-128and a maximum value of127.doubleA double-precision 64-bit IEEE 754 floating point.floatA single-precision 32-bit IEEE 754 floating point.

Number byte, short, integer, long float, double store_source indexNo : boost null_value include_in_all_all ignore_malformedfalse true coerce false true ,

Date

Date type boolean PUT my_index{ "mappings": { "my_type": { "properties": { "date": { "type": "date" } } } }}

Date multi Format date PUT my_index{ "mappings": { "my_type": { "properties": { "date": { "type": "date", "format": "yyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis" } } } }}

Date() : symbol(yyyy), (mm), (dd), (hh), (mm), (ss), (SSS) G-AD/BCA/ AM/PMC h 12YH- 24w k(1~24)e() 1 mE()- MonsySMz-UTCd- Z= +000D -

Date type boolean PUT my_index/my_type/1{ "date": "2015-01-01" }

PUT my_index/my_type/2{ "date": "2015-01-01T12:10:30Z" }

PUT my_index/my_type/3{ "date": 1420070400001 }

GET my_index/_search{ "sort": { "date": "asc"} }Asc sort

This document uses a plain date.This document includes a time.This document uses milliseconds-since-the-epoch.Note that thesortvalues that are returned are all in milliseconds-since-the-epoch.

Date() byte, short, integer, long float, double store_source indexNo : boost null_value include_in_all_all ignore_malformed true format

Bool

Boolean type boolean PUT my_index{ "mappings": { "my_type": { "properties": { "is_published": { "type": "boolean" } } } }}False valuesfalse,"false","off","no","0",""(empty string),0,0.0True valuesAnything that isnt false.

Boolean type boolean PUT my_index/my_type/1{ "is_published": true }

GET my_index/_search{ "query": { "term": { "is_published": 1 } }} true 1

Boolean true false store_source indexNo : boost null_value include_in_all_all

Binary

Binary Binary binary PUT my_index{ "mappings": { "my_type": { "properties": { "name": { "type": "string" }, "blob": { "type": "binary" } } } }}

PUT my_index/my_type/1{ "name": "Some binary blob", "blob": "U29tZSBiaW5hcnkgYmxvYg==" }

binary base64 binary binary store_source compress true compress_threshold

object type

(object) , { : { : : } }

(object) Manager , name inner PUT my_index{ "mappings": { "my_type": { "properties": { "region": { "type": "string", "index": "not_analyzed" }, "manager": { "properties": { "age": { "type": "integer" }, "name": { "properties": { "first": { "type": "string" }, "last": { "type": "string" } } } } } } } }}PUT my_index/my_type/1{ "region": "US", "manager": { "age": 30, "name": { "first": "John", "last": "Smith" } }}

(object) , dynamic true : . false: strict: enabled false include_in_all_all

nested object type

(nested) Mapping field type nested

(nested) Mapping field type nested

(nested) nested { : [ { : : }, { : : },

] }

(nested) Mapping field type nested

(nested)

(nested)

Array type

ARRAYElasticsearch, 0 . an array of strings: [ "one", "two" ]an array of integers: [ 1, 2 ]an array of arrays: [ 1, [ 2, 3 ]] which is the equivalent of [ 1, 2, 3 ]an array of objects: [ { "name": "Mary", "age": 12 }, { "name": "John", "age": 10 }]

Mapping Array mappings

lists, tags, message

Array non-array

Tags array wow

type

(geo_point) lat_lon true lat,lon geohash true geohash normalize true normalize_lat false normalize_lon false validate normalize false true validate_lat true validate_lon true geohash_prefix true geohash_precision geohash_prefix true

(geo_shape) , , , precision distance_error

(multi field) fields { properies : { : { fields : { : { } } } }}

(token_count) { properies : { : { fields : { tokens : { type : token_count, store : true, analyzer : standard } } } }}

count : 1Mapping length token_count

count : 2 2

count : 3 token_count 3

(copy_to) , store true { properies : { 1 : {type: string, copy_to : pk_data} 2 : {type: string, copy_to : pk_data} pk_data : {type : string, store : true} }}1 2 pk_data

Moon Yong Joon

Index(dahl) dahl curl XPUT localhost:9200/dahl

curl XGET localhost:9200/dahl

{ "dahl": { "aliases": {}, "mappings": {}, "settings": { "index": { "creation_date": "1464920538785", "number_of_shards": "5", "number_of_replicas": "1", "uuid": "46BdJFAFQxCcD0Kii0ldWw", "version": { "created": "2030399" } } }, "warmers": {} }}

TypeMapping type curl XPUT localhost:9200/dahl/_mapping/moon -d { "properties": { "name": { "type": "string" } }}

curl XGET localhost:9200/dahl/moon

{ "dahl": { "mappings": { "moon": { "properties": { "name": { "type": "string" } } } } }}

TypeIndex type Mapping post

my_index my_type put your_type

Document

Document Mapping id 1 curl XPUT localhost:9200/dahl/moon/1 -d { "name": "dahlmoon"}

{ "_index": "dahl", "_type": "moon", "_id": "1", "_version": 1, "_shards": { "total": 2, "successful": 1, "failed": 0 }, "created": true}

Document : op_typePUT op_type curl XPUT localhost:9200/dahl/moon/3?op_type=create -d { "name": "dahl moon"}

{"_index":"dahl","_type":"moon","_id":"3","_version":1,"_shards":{"total":2,"successful":1,"failed":0},"created":true}

# curl XPUT localhost:9200/dahl/moon/3?op_type=create -d { "name": "dahl moon"}

{"error":{"root_cause":[{"type":"document_already_exists_exception","reason":"[moon][3]: document already exists","shard":"4","index":"dahl"}],"type":"document_already_exists_exception","reason":"[moon][3]: document already exists","shard":"4","index":"dahl"},"status":409}

Document : _createPUT _create curl XPUT localhost:9200/dahl/moon/4/_create -d { "name": "dahl yong moon"}

{"_index":"dahl","_type":"moon","_id":"4","_version":1,"_shards":{"total":2,"successful":1,"failed":0},"created":true}

# curl XPUT localhost:9200/dahl/moon/4/_create -d { "name": "dahl yong moon"}

{"error":{"root_cause":[{"type":"document_already_exists_exception","reason":"[moon][4]: document already exists","shard":"2","index":"dahl"}],"type":"document_already_exists_exception","reason":"[moon][4]: document already exists","shard":"2","index":"dahl"},"status":409}

Id

Id _id id

curl XPOST localhost:9200//website/blog/ -d { "title": "My second blog entry", "text": "Still trying this out...", "date": "2014/01/01"}

{ "_index": "website", "_type": "blog", "_id": "AVUjaeueQIy_M2v0EEWe", "_version": 1, "_shards": { "total": 2, "successful": 1, "failed": 0 }, "created": true}

Document , id document

curl XGET localhost:9200/dahl/moon/1

{ "_index": "dahl", "_type": "moon", "_id": "1", "_version": 1, "found": true, "_source": { "name": "dahlmoon" }}

Document (_source) _source

curl XGET localhost:9200/dahl/moon/1

{ "_index": "dahl", "_type": "moon", "_id": "1", "_version": 1, "found": true, "_source": { "name": "dahlmoon" }}

curl XGET localhost:9200/dahl/moon/1 /_source

{ "name": "dahlmoon"}

?_source=

curl XGET localhost:9200/dahl/moon/1

{ "_index": "dahl", "_type": "moon", "_id": "1", "_version": 1, "found": true, "_source": { "name": "dahlmoon" }}

curl XGET localhost:9200/dahl/moon/1 ?_source= name

{"_index":"dahl","_type":"moon","_id":"1","_version":1,"found":true,"_source":{"name":"dahlmoon"}}

-1 id 404 not found

#Head 124 id C:\search>curl -XHEAD localhost:9200/books/book/124

Warning: Setting custom HTTP method to HEAD with -X/--request may not work theWarning: way you want. Consider using -I/--head instead.

#-i C:\search>curl -i -XHEAD localhost:9200/books/book/124Warning: Setting custom HTTP method to HEAD with -X/--request may not work theWarning: way you want. Consider using -I/--head instead.HTTP/1.1 404 Not FoundContent-Type: text/plain; charset=UTF-8Content-Length: 0

-2 -I json

#-i elasticsearch body

C:\search>curl -i localhost:9200/books/book/124HTTP/1.1 404 Not FoundContent-Type: application/json; charset=UTF-8Content-Length: 59{"_index":"books","_type":"book","_id":"124","found":false}

#--head body C:\search>curl --head localhost:9200/books/book/124HTTP/1.1 404 Not FoundContent-Type: text/plain; charset=UTF-8Content-Length: 0

id put . created false

curl XPUT localhost:9200/website/blog/123 d {"title": "My first blog entry","text": "I am starting to get the hang of this dahlllll...","date": "2014/01/02","author" : "dahl"}

{"_index":"website","_type":"blog","_id":"123","_version":2,"_shards":{"total":2,"successful":1,"failed":0},"created":false}

Delete id

curl XDELETE localhost:9200/dahl/moon/4

{"found":true,"_index":"dahl","_type":"moon","_id":"4","_version":2,"_shards":{"total":2,"successful":1,"failed":0}}

# id # mapping

curl XPOST localhost:9200/dahl/moon/4 -d {"name" : "dahl yong moon "}

{"_index":"dahl","_type":"moon","_id":"4","_version":3,"_shards":{"total":2,"successful":1,"failed":0},"created":true}

index Delete index mapping

curl XDELETE localhost:9200/dahl

{"acknowledged":true}

#index mapping # 1 curl XPOST localhost:9200/dahl/moon1/1 -d {"name" : "dahl yong moon "}

{"_index":"dahl","_type":"moon1","_id":"1","_version":1,"_shards":{"total":2,"successful":1,"failed":0},"created":true}

Bulk

Moon Yong Joon

Bulk

Bulk action request { action: { metadata }}\n{ request body }\n{ action: { metadata }}\n{ request body }\nMetadat Mapping (_index, _type )

Request body update { "delete": { "_index": "website", "_type": "blog", "_id": "123" }}{ "create": { "_index": "website", "_type": "blog", "_id": "123" }}{ "title": "My first blog post" }{ "index": { "_index": "website", "_type": "blog" }}{ "title": "My second blog post" }{ "update": { "_index": "website", "_type": "blog", "_id": "123", "_retry_on_conflict" : 3} }{ "doc" : {"title" : "My updated blog post"} }

ActionBulk Method ActionRequest body index , create , update deleteN/A

Bulk

Bulk action request curl XPOST host:port/{index}/{type}/_bulk d {} curl XPOST host:port/{index}/{type}/_bulk __data-binary @{}

curl XPOST host:port/{index}/_bulk d {} curl XPOST host:port/{index}/_bulk __data-binary @{}

curl XPOST host:port/_bulk d {} curl XPOST host:port/_bulk __data-binary @{}

Bulk , ,

{ "delete": { "_index": "website", "_type": "blog", "_id": "123" }}{ "create": { "_index": "website", "_type": "blog", "_id": "123" }}{ "title": "My first blog post" }{ "index": { "_index": "website", "_type": "blog" }}{ "title": "My second blog post" }{ "update": { "_index": "website", "_type": "blog", "_id": "123", "_retry_on_conflict" : 3} }{ "doc" : {"title" : "My updated blog post"} }{"took":43,"errors":false,"items":[{"delete":{"_index":"website","_type":"blog","_id":"123","_version":3,"_shards":{"total":2,"successful":1,"failed":0},"status":200,"found":true}},{"create":{"_index":"website","_type":"blog","_id":"123","_version":4,"_shards":{"total":2,"successful":1,"failed":0},"status":201}},{"create":{"_index":"website","_type":"blog","_id":"AVUj6JnRQIy_M2v0EEWo","_version":1,"_shards":{"total":2,"successful":1,"failed":0},"status":201}}]}Request body

Bulk (_id )

localhost:9200/my_store/products/_bulk , index, type _id

3 index

Mappings

Moon Yong Joon

Mapping

Mapping { "mappings" : { "" : { "" : { } .. } } }

Mapping Mapping

Mapping Mapping

Mapping Elasticsearch PUT / -d { "mappings" : { "" : { "" : { } .. } } }

1 type properies { "books": { "mappings": { "book": { "properties": { "author": { "type": "string" }, "category": { "type": "string" }, "date": { "type": "date", "format": "strict_date_optional_time||epoch_millis" }, "pages": { "type": "long" }, "title": { "type": "string" } } } } }}

2 put { "mappings": { "tweet" : { "properties" : { "tweet" : { "type" : "string", "analyzer": "english" }, "date" : { "type" : "date" }, "name" : { "type" : "string" }, "user_id" : { "type" : "long" } } } }}

Mapping

Mapping Type _mapping API GET //_mapping?pretty

GET ///_mapping?pretty

Mapping : index localhost:9200/books/_mappings?pretty

Mapping : localhost:9200/books/_mappings/book?pretty

type mapping curl XGET localhost:9200/books/book/11?pretty

{ "_index": "books", "_type": "book", "_id": "11", "_version": 1, "found": true, "_source": { "title": "Elasticsearch Guide", "author": [ "lee" ], "date": "2014-05-01", "pages": 300, "category": "ICT" }}

Mapping

Mapping Type _mapping API GET //_mapping/ -d { : { properties : { } }

}

Mapping -1 { "properties" : { "tag" : { "type" : "string", "index": "not_analyzed" } }}

Meta fields

Moon Yong Joon

Identity meta-fields

_index _type _index _type { "_index": "books", "_type": "book",

"_id": "11", "_version": 1, "found": true, "_source": { "title": "Elasticsearch Guide", "author": [ "lee" ], "date": "2014-05-01", "pages": 300, "category": "ICT" }}

Document source meta-fields

_source _source

{ "_index": "books", "_type": "book",

"_id": "11", "_version": 1, "found": true, "_source": { "title": "Elasticsearch Guide", "author": [ "lee" ], "date": "2014-05-01", "pages": 300, "category": "ICT" }}

_source _source enabled false

Curl XPUT / -d { mappings : { : { _source : { enabled : false } } } }}

_source includes Curl XPUT / -d { mappings : { : { _source : { includes : [,,] } } } }}

_source excludes * Curl XPUT / -d { mappings : { : { _source : { excludes : [ *] } } }}

Indexing meta-fields

_all Curl XPUT / -d { mappings : { : { _all : {enabled : true} properties : { 1 : { include_in_all : true , type : string 2 : { include_in_all : false , type : string

} } }}

_timestamp timestamp Curl XPUT / -d { mappings : { : { _timestamp : { enabled : true store : true } } }}

_ttl(time to live) index - d(), m(),h(),s(), ms(1/1000), wCurl XPUT / -d { mappings : { : { _ttl : { enabled : true default : 2d } } }}

_analyzer Curl XPUT / -d { mappings : { : { _analyzer : {path : } properties : { 1 : { type : string 2 : { type : string

} } }}

URI

Moon Yong Joon

_search API

_search _search /_search # /gb/_search # gb /gb,us/_search # gb,us /g*,u*/_search # g*,u*

/gb/user/_search # gb, user /gb,us/user,tweet/_search # gb, us user, tweet /_all/user,tweet/_search # user tweet

_search type localhost:9200/website/blog/_search?pretty{ "took" : 6, "timed_out" : false, "_shards" : { "total" : 5, "successful" : 5, "failed" : 0 }, "hits" : { "total" : 3, "max_score" : 1.0, "hits" : [ { "_index" : "website", "_type" : "blog", "_id" : "123", "_score" : 1.0, "_source" : { "title" : "My first blog post" } }, .Get

_search size from GET /_search?size=5GET /_search?size=5&from=5GET /_search?size=5&from=10

_search size=3 12 3

Query string

Query string _search?q= : GET localhost:9200/_all/_search?q=

GET localhost:9200/_all/_search?q=:

GET localhost:9200/_all/_search?q=:&:

Query string : localhost:9200/_all/_search?q=elasticsearch

Query string : :localhost:9200/_all/_search?q=title:elasticsearch

Query string : (&)localhost:9200/_all/_search?q=title:elasticsearch&pages:300

Query string : (+)localhost:9200/_all/_search?q=date:>2014-03-01+pages:300&pretty 2

date:>2014-03-01&pages:300 3date:>2014-03-01+pages:300 4

Query string : containlocalhost:9200/_all/_search?q=pages:(300 5000)

blank

Query string : localhost:9200/_all/_search?q=date:>2014-03-01

Query string : AND/ORPages 300 or 500 - (%20)

Query string : df df(default field)

q= df

Query string : default op AND, OR default operator

blank(OR) default_operator

OR/AND

Query DSL

Moon Yong Joon

_search API

_search _search /_search # /gb/_search # gb /gb,us/_search # gb,us /g*,u*/_search # g*,u*

/gb/user/_search # gb, user /gb,us/user,tweet/_search # gb, us user, tweet /_all/user,tweet/_search # user tweet

Query DSL

Query DSLQuery DSL GET /_search{ "query": YOUR_QUERY_HERE}

curl XGET localhost:9200/_search d { "query" : { "match" : { "title" : "elasticsearch" } }}

Query DSL : leaf Query query { QUERY_NAME: { FIELD_NAME: { ARGUMENT: VALUE, ARGUMENT: VALUE,... } }}{ "query": { "match": { "tweet": "elasticsearch" } }}

Query DSL : compound Query query { "query" : { "bool": { "must": { "match": { "title": "elasticsearch" }}, "must_not": { "match": { "name": "lee" }}, "should": { "match": { "pages": 300 }} } }}

Queries and FiltersQuery Filter Filter Yes/No

Query

Query DSL: filter

Moon Yong Joon

term

Term ( numbers, dates, Booleans, or not_analyzed exact-value string fields){ " filter " : { "term": { "pages": 5000 } }} Term term

Term : Term filter prefix . prefix query { filter" : { "term": { "title" : "ela" }

}}

Term : price array

terms

Terms Term { "filter" : { "terms": { "pages": [ 300, 5000 ] } }}2 array

range

range Filter { filter" : { "range": { "pages": { "gte": 300, "lte": 5000 } } }} gt : Greater than gte : Greater than or equal to lt : Less than lte : Less than or equal to

and,or, not

not Filter { "filter" : { "not" : { "range": { "pages": { "gte": 500, "lte": 5000 } } } }

}

and/or Filter field { "filter" : { "and" : [ { "range": { "pages": { "gte": 300, "lte": 5000 } } }, { "term" : { "title" : "elasticsearch"} } ] }}

bool

bool filter { "filter" : { "bool": { "must" : { "term" :{"title": "big"} }, "must_not" : { "term" : { "title" : "elasticsearch"} }, "should" :{ "term" :{"plot" : "elasticsearch"} } } }}must , AND .must_not NOT should , OR

bool filter title big plot elasticsearch title elasticsearch

Query DSL: query

Moon Yong Joon

Exist

exists and missing Filters { "query" : { "exists": { "field": "title" }

}}

Match

Match Query :

Match Query : (and) query operator query Operator or

Match Query : (or) query operator query Operator or

Match Query : phrase type phrase

Match Query :minimum_should_match { "query": { "match": { "title": { "query": "quick brown dog", "minimum_should_match": "75%" } } }}

match_all

match_all Query { "query" : { "match_all": {}

}}

multi_match

multi_match Query { "query" : { "multi_match": { "fields" : ["title","plot"], "query" : "elasticsearch" }

}}

multi_match Query Fields query

bool

bool query { "query" : { "bool": { "must" : { "term" :{"title": "big"} }, "must_not" : { "term" : { "title" : "elasticsearch"} }, "should" :{ "term" :{"plot" : "elasticsearch"} } } }}must , AND .must_not NOT should , OR

bool query : match(or) bool Match 2 term bool should 2 { "match": { "title": "brown fox"}}{ "bool": { "should": [ { "term": { "title": "brown" }}, { "term": { "title": "fox" }} ] }}

bool query : match(and) bool Match 2 term and bool must 2 { "match": { "title": { "query": "brown fox", "operator": "and" } }}{ "bool": { "must": [ { "term": { "title": "brown" }}, { "term": { "title": "fox" }} ] }}

bool query : match(%) bool Match 3 term % bool should 3 minium match { "match": { "title": { "query": "quick brown fox", "minimum_should_match": "75%" } }}{ "bool": { "should": [ { "term": { "title": "brown" }}, { "term": { "title": "fox" }}, { "term": { "title": "quick" }} ], "minimum_should_match": 2 }}

Query_string

query_string query 1Query string query : : big { "query" : { "query_string": { "query" : "title: big" }

}}

query_string query 2 query string query , : big data { "query" : { "query_string": { "query" : "big data", "default_field" : "title", "default_operator" : "and" }

}}

query_string query 3 query string query , : big data { "query" : { "query_string": { "query" : "big data", "default_field" : "title", "default_operator" : " }

}}

prefix

query_string query 1Term filter { "query" : { "prefix": { "title" : "ela" }

}}

range

range query { query" : { "range": { "pages": { "gte": 300, "lte": 5000 } } }} gt : Greater than gte : Greater than or equal to lt : Less than lte : Less than or equal to

fuzzy

fuzzy query : bag big { "query" : { "fuzzy": { "title": "bag" } }}

fuzzy query : value fuzziness +/- (200) { "query" : { "fuzzy": { "pages" : { "value" : 500, "fuzziness" : 200 } } }}

nested

bool query : Bool match { "query": { "bool": { "must": { "match": { "title": "quick" }}, "must_not": { "match": { "title": "lazy" }}, "should": [ { "match": { "title": "brown" }}, { "match": { "title": "dog" }} ] } }}

bool query title big plot elasticsearch title elasticsearch

(nested)

(nested) - 1

(nested) - 2 (Alice White)

(nested) - inner Inner_hits

boosting

boost Match (boost) { "query": { "bool": { "must": { "match": { "content": { "query": "full text search", "operator": "and" } } }, "should": [ { "match": { "content": { "query": "Elasticsearch", "boost": 3 } }}, { "match": { "content": { "query": "Lucene", "boost": 2 } }} ] } }}

Query DSL: filterdMoon Yong Joon

filetered

filteredQuery filter

Query filter

Filtered 3 price 20

Filetered:term

Filtered: term term filter :

Filtered: analyzed productID term filter

Filtered: term filter { "mappings" : { "products" : { "properties" : { "productID" : { "type" : "string", "index" : "not_analyzed" } } } }}

Filetered:bool

Filtered : bool price=10 or price=20 price=30

Filetered:nested bool

Filtered : nested bool price=10 or price=30

Filetered: Equals Exactly

Filtered : Equals Exactly bool must term AND POST /my_index/my_type/_search{ "query": { "filtered" : { "filter" : { "bool" : { "must" : [ { "term" : { "tags" : "search" } }, { "term" : { "tag_count" : 1 } } ] } } } }} tags & tag_count

Filetered: date range

Filtered : date range now 1h date

Filtered : date operator || + 1M

Filetered: string range

Filtered : string range

Filetered:existing

Filtered : null

Filtered :exist field

Filtered : missing field null

Filtered : object field object object. { "bool": { "should": [ { "exists": { "field": { "name.first" }}}, { "exists": { "field": { "name.last" }}} ] }}

Query DSL: _validate

Moon Yong Joon

validate

_validate API_validate API query localhost:9200/books/_validate/query

_validate API : explain_validate API query explain localhost:9200/books/_validate/query?explain&pretty

_validate API : error _validate API error explain

sort

Moon Yong Joon

URI sort

sortURI sort sorting order localhost:9200/books/_search?sort=date:desc&sort=_score&q=plot:elasticsearch&pretty

Sort URI sort

QueryDSL sort

sortSort (desc/asc)

Sort Sort _score sort

_score

Sort date mili

Sort : multi field Sort (desc/asc) : _score sort

Sort : multi field Sort (desc/asc)

_score

date, _score 2 sortting