ElasticSearch operation command Daquan

Creating indexes and maps

1, manually create an index

curl -XPUT ‘localhost:9200/new-index’

2, get map

curl ‘localhost:9200/get-together/_mapping/group?pretty’

Define a new mapping

curl -XPUT ‘localhost:9200/get-together/_mappering/new-events’ -d ‘{
“new-event”:{
“propeties”:{
“host”:{
“type”: “string”
}}}}’

3, the search data acquisition
ES uses _all field defaults, index the contents of all fields

curl ‘localhost:9200/get-together/group/_search?
q=elasticsearch
&field=name,location
&size=1
&pretty’

4, in an index, multiple types of search (new version obsolete type)

curl “localhost:9200/get-together/group,event/_search?q=elasticsearch&pretty”

5, search across multiple indexes

curl “localhost:9200/get-together,other-index/_search?q=elasticsearch&pretty”

6, the search can be used as an index _all placeholder in an index of all type

curl “localhost:9200/_all/type/_search”

7, timeout (default never timeout) specified query

curl “localhost:9200/get-together/group/_search?q=elasticsearch&pretty&timeout=3s”

8, run a query type query_string

curl ‘localhost:9200/get-together/group/_search?pretty’ -d ‘{
“query”:{
“query_string”:{
“query”: “elasticsearch san francisco”,
“default_field”: “name”,
“default_operatior”:“AND”
}}
}’

9, term queries, if find 'elastic search' is only a word in the name field, term query may be faster

curl ‘localhost:9200/get-together/group/_search?pretty’ -d ‘{
“query”:{
“term”:{
“name”: “elasticsearch”
}}
}’

10, using a filter, if the score is not interested in the search, you can use the query filters, filter only care about the results of matches, and can be cached, so the relatively faster

curl ‘localhost:9200/get-together/group/_search?pretty’ -d ‘{
“query”:{
“filted”:{
“filter”:{
“term”:{
“name”:“elasticsearch”
}}
}}’

11, aggregate query

curl localhost:9200/get-together/group/_search?pretty -d ‘{
“aggregation”:{
“organizers”:{
“term”:{
“field”:“organizer”}
}
}}’

12, access to the document by ID

curl ‘localhost:9200/get-together/group/1?pretty’

Published 55 original articles · won praise 14 · views 20000 +

Guess you like

Origin blog.csdn.net/qq422243639/article/details/100578653