- About
- Browser Builds
- Quick Start
- API Conventions
- Configuration
- SSL and Authentication
- Extending
- Extensions
- setup logging
- Contributing
- 7.6 API
bulk
clearScroll
count
create
delete
deleteByQuery
deleteByQueryRethrottle
deleteScript
exists
existsSource
explain
fieldCaps
get
getScript
getSource
index
info
mget
msearch
msearchTemplate
mtermvectors
ping
putScript
rankEval
reindex
reindexRethrottle
renderSearchTemplate
scriptsPainlessExecute
scroll
search
searchShards
searchTemplate
termvectors
update
updateByQuery
updateByQueryRethrottle
cat.aliases
cat.allocation
cat.count
cat.fielddata
cat.health
cat.help
cat.indices
cat.master
cat.nodeattrs
cat.nodes
cat.pendingTasks
cat.plugins
cat.recovery
cat.repositories
cat.segments
cat.shards
cat.snapshots
cat.tasks
cat.templates
cat.threadPool
cluster.allocationExplain
cluster.getSettings
cluster.health
cluster.pendingTasks
cluster.putSettings
cluster.remoteInfo
cluster.reroute
cluster.state
cluster.stats
indices.analyze
indices.clearCache
indices.clone
indices.close
indices.create
indices.delete
indices.deleteAlias
indices.deleteTemplate
indices.exists
indices.existsAlias
indices.existsTemplate
indices.existsType
indices.flush
indices.flushSynced
indices.forcemerge
indices.get
indices.getAlias
indices.getFieldMapping
indices.getMapping
indices.getSettings
indices.getTemplate
indices.getUpgrade
indices.open
indices.putAlias
indices.putMapping
indices.putSettings
indices.putTemplate
indices.recovery
indices.refresh
indices.rollover
indices.segments
indices.shardStores
indices.shrink
indices.split
indices.stats
indices.updateAliases
indices.upgrade
indices.validateQuery
ingest.deletePipeline
ingest.getPipeline
ingest.processorGrok
ingest.putPipeline
ingest.simulate
nodes.hotThreads
nodes.info
nodes.reloadSecureSettings
nodes.stats
nodes.usage
snapshot.create
snapshot.createRepository
snapshot.delete
snapshot.deleteRepository
snapshot.get
snapshot.getRepository
snapshot.restore
snapshot.status
snapshot.verifyRepository
tasks.cancel
tasks.get
tasks.list
- 7.5 API
bulk
clearScroll
count
create
delete
deleteByQuery
deleteByQueryRethrottle
deleteScript
exists
existsSource
explain
fieldCaps
get
getScript
getSource
index
info
mget
msearch
msearchTemplate
mtermvectors
ping
putScript
rankEval
reindex
reindexRethrottle
renderSearchTemplate
scriptsPainlessExecute
scroll
search
searchShards
searchTemplate
termvectors
update
updateByQuery
updateByQueryRethrottle
cat.aliases
cat.allocation
cat.count
cat.fielddata
cat.health
cat.help
cat.indices
cat.master
cat.nodeattrs
cat.nodes
cat.pendingTasks
cat.plugins
cat.recovery
cat.repositories
cat.segments
cat.shards
cat.snapshots
cat.tasks
cat.templates
cat.threadPool
cluster.allocationExplain
cluster.getSettings
cluster.health
cluster.pendingTasks
cluster.putSettings
cluster.remoteInfo
cluster.reroute
cluster.state
cluster.stats
indices.analyze
indices.clearCache
indices.clone
indices.close
indices.create
indices.delete
indices.deleteAlias
indices.deleteTemplate
indices.exists
indices.existsAlias
indices.existsTemplate
indices.existsType
indices.flush
indices.flushSynced
indices.forcemerge
indices.get
indices.getAlias
indices.getFieldMapping
indices.getMapping
indices.getSettings
indices.getTemplate
indices.getUpgrade
indices.open
indices.putAlias
indices.putMapping
indices.putSettings
indices.putTemplate
indices.recovery
indices.refresh
indices.rollover
indices.segments
indices.shardStores
indices.shrink
indices.split
indices.stats
indices.updateAliases
indices.upgrade
indices.validateQuery
ingest.deletePipeline
ingest.getPipeline
ingest.processorGrok
ingest.putPipeline
ingest.simulate
nodes.hotThreads
nodes.info
nodes.reloadSecureSettings
nodes.stats
nodes.usage
snapshot.create
snapshot.createRepository
snapshot.delete
snapshot.deleteRepository
snapshot.get
snapshot.getRepository
snapshot.restore
snapshot.status
snapshot.verifyRepository
tasks.cancel
tasks.get
tasks.list
- 7.4 API
bulk
clearScroll
count
create
delete
deleteByQuery
deleteByQueryRethrottle
deleteScript
exists
existsSource
explain
fieldCaps
get
getScript
getSource
index
info
mget
msearch
msearchTemplate
mtermvectors
ping
putScript
rankEval
reindex
reindexRethrottle
renderSearchTemplate
scriptsPainlessExecute
scroll
search
searchShards
searchTemplate
termvectors
update
updateByQuery
updateByQueryRethrottle
cat.aliases
cat.allocation
cat.count
cat.fielddata
cat.health
cat.help
cat.indices
cat.master
cat.nodeattrs
cat.nodes
cat.pendingTasks
cat.plugins
cat.recovery
cat.repositories
cat.segments
cat.shards
cat.snapshots
cat.tasks
cat.templates
cat.threadPool
cluster.allocationExplain
cluster.getSettings
cluster.health
cluster.pendingTasks
cluster.putSettings
cluster.remoteInfo
cluster.reroute
cluster.state
cluster.stats
indices.analyze
indices.clearCache
indices.clone
indices.close
indices.create
indices.delete
indices.deleteAlias
indices.deleteTemplate
indices.exists
indices.existsAlias
indices.existsTemplate
indices.existsType
indices.flush
indices.flushSynced
indices.forcemerge
indices.get
indices.getAlias
indices.getFieldMapping
indices.getMapping
indices.getSettings
indices.getTemplate
indices.getUpgrade
indices.open
indices.putAlias
indices.putMapping
indices.putSettings
indices.putTemplate
indices.recovery
indices.refresh
indices.rollover
indices.segments
indices.shardStores
indices.shrink
indices.split
indices.stats
indices.updateAliases
indices.upgrade
indices.validateQuery
ingest.deletePipeline
ingest.getPipeline
ingest.processorGrok
ingest.putPipeline
ingest.simulate
nodes.hotThreads
nodes.info
nodes.reloadSecureSettings
nodes.stats
nodes.usage
snapshot.create
snapshot.createRepository
snapshot.delete
snapshot.deleteRepository
snapshot.get
snapshot.getRepository
snapshot.restore
snapshot.status
snapshot.verifyRepository
tasks.cancel
tasks.get
tasks.list
- 7.3 API
bulk
clearScroll
count
create
delete
deleteByQuery
deleteByQueryRethrottle
deleteScript
exists
existsSource
explain
fieldCaps
get
getScript
getSource
index
info
mget
msearch
msearchTemplate
mtermvectors
ping
putScript
rankEval
reindex
reindexRethrottle
renderSearchTemplate
scriptsPainlessExecute
scroll
search
searchShards
searchTemplate
termvectors
update
updateByQuery
updateByQueryRethrottle
cat.aliases
cat.allocation
cat.count
cat.fielddata
cat.health
cat.help
cat.indices
cat.master
cat.nodeattrs
cat.nodes
cat.pendingTasks
cat.plugins
cat.recovery
cat.repositories
cat.segments
cat.shards
cat.snapshots
cat.tasks
cat.templates
cat.threadPool
cluster.allocationExplain
cluster.getSettings
cluster.health
cluster.pendingTasks
cluster.putSettings
cluster.remoteInfo
cluster.reroute
cluster.state
cluster.stats
indices.analyze
indices.clearCache
indices.close
indices.create
indices.delete
indices.deleteAlias
indices.deleteTemplate
indices.exists
indices.existsAlias
indices.existsTemplate
indices.existsType
indices.flush
indices.flushSynced
indices.forcemerge
indices.get
indices.getAlias
indices.getFieldMapping
indices.getMapping
indices.getSettings
indices.getTemplate
indices.getUpgrade
indices.open
indices.putAlias
indices.putMapping
indices.putSettings
indices.putTemplate
indices.recovery
indices.refresh
indices.rollover
indices.segments
indices.shardStores
indices.shrink
indices.split
indices.stats
indices.updateAliases
indices.upgrade
indices.validateQuery
ingest.deletePipeline
ingest.getPipeline
ingest.processorGrok
ingest.putPipeline
ingest.simulate
nodes.hotThreads
nodes.info
nodes.reloadSecureSettings
nodes.stats
nodes.usage
snapshot.create
snapshot.createRepository
snapshot.delete
snapshot.deleteRepository
snapshot.get
snapshot.getRepository
snapshot.restore
snapshot.status
snapshot.verifyRepository
tasks.cancel
tasks.get
tasks.list
- 7.2 API
bulk
clearScroll
count
create
delete
deleteByQuery
deleteByQueryRethrottle
deleteScript
exists
existsSource
explain
fieldCaps
get
getScript
getSource
index
info
mget
msearch
msearchTemplate
mtermvectors
ping
putScript
rankEval
reindex
reindexRethrottle
renderSearchTemplate
scriptsPainlessContext
scriptsPainlessExecute
scroll
search
searchShards
searchTemplate
termvectors
update
updateByQuery
updateByQueryRethrottle
cat.aliases
cat.allocation
cat.count
cat.fielddata
cat.health
cat.help
cat.indices
cat.master
cat.nodeattrs
cat.nodes
cat.pendingTasks
cat.plugins
cat.recovery
cat.repositories
cat.segments
cat.shards
cat.snapshots
cat.tasks
cat.templates
cat.threadPool
cluster.allocationExplain
cluster.getSettings
cluster.health
cluster.pendingTasks
cluster.putSettings
cluster.remoteInfo
cluster.reroute
cluster.state
cluster.stats
indices.analyze
indices.clearCache
indices.close
indices.create
indices.delete
indices.deleteAlias
indices.deleteTemplate
indices.exists
indices.existsAlias
indices.existsTemplate
indices.existsType
indices.flush
indices.flushSynced
indices.forcemerge
indices.get
indices.getAlias
indices.getFieldMapping
indices.getMapping
indices.getSettings
indices.getTemplate
indices.getUpgrade
indices.open
indices.putAlias
indices.putMapping
indices.putSettings
indices.putTemplate
indices.recovery
indices.refresh
indices.rollover
indices.segments
indices.shardStores
indices.shrink
indices.split
indices.stats
indices.updateAliases
indices.upgrade
indices.validateQuery
ingest.deletePipeline
ingest.getPipeline
ingest.processorGrok
ingest.putPipeline
ingest.simulate
nodes.hotThreads
nodes.info
nodes.reloadSecureSettings
nodes.stats
nodes.usage
snapshot.create
snapshot.createRepository
snapshot.delete
snapshot.deleteRepository
snapshot.get
snapshot.getRepository
snapshot.restore
snapshot.status
snapshot.verifyRepository
tasks.cancel
tasks.get
tasks.list
- 7.1 API
bulk
clearScroll
count
create
delete
deleteByQuery
deleteByQueryRethrottle
deleteScript
exists
existsSource
explain
fieldCaps
get
getScript
getSource
index
info
mget
msearch
msearchTemplate
mtermvectors
ping
putScript
rankEval
reindex
reindexRethrottle
renderSearchTemplate
scriptsPainlessExecute
scroll
search
searchShards
searchTemplate
termvectors
update
updateByQuery
updateByQueryRethrottle
cat.aliases
cat.allocation
cat.count
cat.fielddata
cat.health
cat.help
cat.indices
cat.master
cat.nodeattrs
cat.nodes
cat.pendingTasks
cat.plugins
cat.recovery
cat.repositories
cat.segments
cat.shards
cat.snapshots
cat.tasks
cat.templates
cat.threadPool
cluster.allocationExplain
cluster.getSettings
cluster.health
cluster.pendingTasks
cluster.putSettings
cluster.remoteInfo
cluster.reroute
cluster.state
cluster.stats
indices.analyze
indices.clearCache
indices.close
indices.create
indices.delete
indices.deleteAlias
indices.deleteTemplate
indices.exists
indices.existsAlias
indices.existsTemplate
indices.existsType
indices.flush
indices.flushSynced
indices.forcemerge
indices.get
indices.getAlias
indices.getFieldMapping
indices.getMapping
indices.getSettings
indices.getTemplate
indices.getUpgrade
indices.open
indices.putAlias
indices.putMapping
indices.putSettings
indices.putTemplate
indices.recovery
indices.refresh
indices.rollover
indices.segments
indices.shardStores
indices.shrink
indices.split
indices.stats
indices.updateAliases
indices.upgrade
indices.validateQuery
ingest.deletePipeline
ingest.getPipeline
ingest.processorGrok
ingest.putPipeline
ingest.simulate
nodes.hotThreads
nodes.info
nodes.reloadSecureSettings
nodes.stats
nodes.usage
snapshot.create
snapshot.createRepository
snapshot.delete
snapshot.deleteRepository
snapshot.get
snapshot.getRepository
snapshot.restore
snapshot.status
snapshot.verifyRepository
tasks.cancel
tasks.get
tasks.list
- 7.0 API
bulk
clearScroll
count
create
delete
deleteByQuery
deleteByQueryRethrottle
deleteScript
exists
existsSource
explain
fieldCaps
get
getScript
getSource
index
info
mget
msearch
msearchTemplate
mtermvectors
ping
putScript
rankEval
reindex
reindexRethrottle
renderSearchTemplate
scriptsPainlessExecute
scroll
search
searchShards
searchTemplate
termvectors
update
updateByQuery
updateByQueryRethrottle
cat.aliases
cat.allocation
cat.count
cat.fielddata
cat.health
cat.help
cat.indices
cat.master
cat.nodeattrs
cat.nodes
cat.pendingTasks
cat.plugins
cat.recovery
cat.repositories
cat.segments
cat.shards
cat.snapshots
cat.tasks
cat.templates
cat.threadPool
cluster.allocationExplain
cluster.getSettings
cluster.health
cluster.pendingTasks
cluster.putSettings
cluster.remoteInfo
cluster.reroute
cluster.state
cluster.stats
indices.analyze
indices.clearCache
indices.close
indices.create
indices.delete
indices.deleteAlias
indices.deleteTemplate
indices.exists
indices.existsAlias
indices.existsTemplate
indices.existsType
indices.flush
indices.flushSynced
indices.forcemerge
indices.get
indices.getAlias
indices.getFieldMapping
indices.getMapping
indices.getSettings
indices.getTemplate
indices.getUpgrade
indices.open
indices.putAlias
indices.putMapping
indices.putSettings
indices.putTemplate
indices.recovery
indices.refresh
indices.rollover
indices.segments
indices.shardStores
indices.shrink
indices.split
indices.stats
indices.updateAliases
indices.upgrade
indices.validateQuery
ingest.deletePipeline
ingest.getPipeline
ingest.processorGrok
ingest.putPipeline
ingest.simulate
nodes.hotThreads
nodes.info
nodes.reloadSecureSettings
nodes.stats
nodes.usage
snapshot.create
snapshot.createRepository
snapshot.delete
snapshot.deleteRepository
snapshot.get
snapshot.getRepository
snapshot.restore
snapshot.status
snapshot.verifyRepository
tasks.cancel
tasks.get
tasks.list
- 6.8 API
bulk
clearScroll
count
create
delete
deleteByQuery
deleteByQueryRethrottle
deleteScript
exists
existsSource
explain
fieldCaps
get
getScript
getSource
index
info
mget
msearch
msearchTemplate
mtermvectors
ping
putScript
rankEval
reindex
reindexRethrottle
renderSearchTemplate
scriptsPainlessExecute
scroll
search
searchShards
searchTemplate
termvectors
update
updateByQuery
updateByQueryRethrottle
cat.aliases
cat.allocation
cat.count
cat.fielddata
cat.health
cat.help
cat.indices
cat.master
cat.nodeattrs
cat.nodes
cat.pendingTasks
cat.plugins
cat.recovery
cat.repositories
cat.segments
cat.shards
cat.snapshots
cat.tasks
cat.templates
cat.threadPool
cluster.allocationExplain
cluster.getSettings
cluster.health
cluster.pendingTasks
cluster.putSettings
cluster.remoteInfo
cluster.reroute
cluster.state
cluster.stats
indices.analyze
indices.clearCache
indices.close
indices.create
indices.delete
indices.deleteAlias
indices.deleteTemplate
indices.exists
indices.existsAlias
indices.existsTemplate
indices.existsType
indices.flush
indices.flushSynced
indices.forcemerge
indices.get
indices.getAlias
indices.getFieldMapping
indices.getMapping
indices.getSettings
indices.getTemplate
indices.getUpgrade
indices.open
indices.putAlias
indices.putMapping
indices.putSettings
indices.putTemplate
indices.recovery
indices.refresh
indices.rollover
indices.segments
indices.shardStores
indices.shrink
indices.split
indices.stats
indices.updateAliases
indices.upgrade
indices.validateQuery
ingest.deletePipeline
ingest.getPipeline
ingest.processorGrok
ingest.putPipeline
ingest.simulate
nodes.hotThreads
nodes.info
nodes.reloadSecureSettings
nodes.stats
nodes.usage
snapshot.create
snapshot.createRepository
snapshot.delete
snapshot.deleteRepository
snapshot.get
snapshot.getRepository
snapshot.restore
snapshot.status
snapshot.verifyRepository
tasks.cancel
tasks.get
tasks.list
- 5.6 API
bulk
clearScroll
count
countPercolate
create
delete
deleteByQuery
deleteScript
deleteTemplate
exists
existsSource
explain
fieldCaps
fieldStats
get
getScript
getSource
getTemplate
index
info
mget
mpercolate
msearch
msearchTemplate
mtermvectors
percolate
ping
putScript
putTemplate
reindex
reindexRethrottle
renderSearchTemplate
scroll
search
searchShards
searchTemplate
suggest
termvectors
update
updateByQuery
cat.aliases
cat.allocation
cat.count
cat.fielddata
cat.health
cat.help
cat.indices
cat.master
cat.nodeattrs
cat.nodes
cat.pendingTasks
cat.plugins
cat.recovery
cat.repositories
cat.segments
cat.shards
cat.snapshots
cat.tasks
cat.templates
cat.threadPool
cluster.allocationExplain
cluster.getSettings
cluster.health
cluster.pendingTasks
cluster.putSettings
cluster.remoteInfo
cluster.reroute
cluster.state
cluster.stats
indices.analyze
indices.clearCache
indices.close
indices.create
indices.delete
indices.deleteAlias
indices.deleteTemplate
indices.exists
indices.existsAlias
indices.existsTemplate
indices.existsType
indices.flush
indices.flushSynced
indices.forcemerge
indices.get
indices.getAlias
indices.getFieldMapping
indices.getMapping
indices.getSettings
indices.getTemplate
indices.getUpgrade
indices.open
indices.putAlias
indices.putMapping
indices.putSettings
indices.putTemplate
indices.recovery
indices.refresh
indices.rollover
indices.segments
indices.shardStores
indices.shrink
indices.stats
indices.updateAliases
indices.upgrade
indices.validateQuery
ingest.deletePipeline
ingest.getPipeline
ingest.processorGrok
ingest.putPipeline
ingest.simulate
nodes.hotThreads
nodes.info
nodes.stats
snapshot.create
snapshot.createRepository
snapshot.delete
snapshot.deleteRepository
snapshot.get
snapshot.getRepository
snapshot.restore
snapshot.status
snapshot.verifyRepository
tasks.cancel
tasks.get
tasks.list
- Changelog
- Host
- Transport
- Errors
- API Param Types
IMPORTANT: elasticsearch.js has been replaced by the new Elasticsearch JavaScript client. We strongly advise you to migrate to the new client. To learn more, see the migration guide.
Searching for documents
editSearching for documents
editA very common use-case for elasticsearch is to sort through large collections of documents in order to find ones that are relevant to a query. In most cases you will use the client’s search()
method to accomplish this.
Elasticsearch Query DSL
editFor many searches you will want to define a search document that tells elasticsearch exactly how to find the documents you are looking for. To do this you will use the elasticsearch query DSL. If you are not familiar with Elasticsearch’s query DSL it is recommended that you research the topic at elasticsearch.org or watch/read one of these introductions:
Now for some examples using the Query DSL.
Simple match query
editFind tweets that have "elasticsearch" in their body field.
client.search({ index: 'twitter', type: 'tweets', body: { query: { match: { body: 'elasticsearch' } } } }).then(function (resp) { var hits = resp.hits.hits; }, function (err) { console.trace(err.message); });
More complex filtered query
editTo power a search form on a public site, you might want to allow the user to specify some text but also limit the documents returned by a few criteria. This is a good use-case for a filtered query.
In this example, request
and response
are Express request and response objects.
var pageNum = request.params.page; var perPage = request.params.per_page; var userQuery = request.params.search_query; var userId = request.session.userId; var searchParams = { index: 'posts', from: (pageNum - 1) * perPage, size: perPage, body: { query: { filtered: { query: { match: { // match the query against all of // the fields in the posts index _all: userQuery } }, filter: { // only return documents that are // public or owned by the current user or: [ { term: { privacy: "public" } }, { term: { owner: userId } } ] } } } } }; client.search(searchParams, function (err, res) { if (err) { // handle error throw err; } response.render('search_results', { results: res.hits.hits, page: pageNum, pages: Math.ceil(res.hits.total / perPage) }); });
You can find a lot more information about filters here