All topics

Elasticsearch interview questions

24 questions with answers. 295 open jobs in India ask for Elasticsearch.

  1. Solr vs. ElasticSearch

    Update

    Now that the question scope has been corrected, I might add something in this regard as well:

    There are many comparisons between Apache Solr and Elasticsearch available, so I'll reference those I found most useful myself, i.e. covering the most important aspects:

    Solr may be the weapon of choice when building standard search applications, but Elasticsearch takes it to the next level with an architecture for creating modern realtime search applications. Percolation is an exciting and innovative feature that singlehandedly blows Solr right out of the water. Elasticsearch is scalable, speedy and a dream to integrate with. Adios Solr, it was nice knowing you. [emphasis mine]

    • At the time this answer was written (2012), the Wikipedia article on Elasticsearch summarized a comparison from the reputed German iX magazine, listing advantages and disadvantages, which pretty much summarizes what has been said in other answers already:

    Advantages:

    • Elasticsearch is distributed. No separate project required. Replicas are near real-time too, which is called "Push replication".
    • ElasticSearch fully supports the near real-time search of Apache Lucene.
    • Handling multitenancy is not a special configuration, where with Solr a more advanced setup is necessary.
    • ElasticSearch introduces the concept of the Gateway, which makes full backups easier.

    Disadvantages:

    • Only one main developer [not applicable anymore according to the current elasticsearch GitHub organization, besides having a pretty active committer base in the first place]
    • No autowarming feature [not applicable anymore according to the new Index Warmup API]

    Initial Answer

    They are completely different technologies addressing completely different use cases, thus cannot be compared at all in any meaningful way:

    Read the rest at the sourceFrom Stack Overflow: asked by Ben ODay, answered by Steffen Opel (CC BY-SA 4.0)

  2. What is the difference between MUST and SHOULD in an Elasticsearch bool query?

    must means: The clause (query) must appear in matching documents. These clauses must match, like logical AND.

    should means: At least one of these clauses must match, like logical OR.

    Basically they are used like logical operators AND and OR. See this.

    Now in a bool query:

    must means: Clauses that must match for the document to be included.

    should means: If these clauses match, they increase the _score; otherwise, they have no effect. They are simply used to refine the relevance score for each document.

    Yes you can use multiple filters inside must.

    From Stack Overflow: asked by user2722667, answered by Utsav Dawn (CC BY-SA 4.0)

  3. Queries vs. Filters

    The difference is simple: filters are cached and don't influence the score, therefore faster than queries. Have a look here too. Let's say a query is usually something that the users type and pretty much unpredictable, while filters help users narrowing down the search results , for example using facets.

    From Stack Overflow: asked by Jonesie, answered by javanna (CC BY-SA 3.0)

  4. What is the difference between Lucene and Elasticsearch?

    Lucene is a Java library. You can include it in your project and refer to its functions using function calls.

    Elasticsearch is a JSON Based, Distributed, web server built over Lucene. Though it's Lucene who is doing the actual work beneath, Elasticsearch provides us a convenient layer over Lucene. Each shard that gets created in Elasticsearch is a separate Lucene instance. So to summarize

    1. Elasticsearch is built over Lucene and provides a JSON based REST API to refer to Lucene features.
    2. Elasticsearch provides a distributed system on top of Lucene. A distributed system is not something Lucene is aware of or built for. Elasticsearch provides this abstraction of distributed structure.
    3. Elasticsearch provides other supporting features like thread-pool, queues, node/cluster monitoring API, data monitoring API, Cluster management, etc.

    From Stack Overflow: asked by Satish, answered by Vineeth Mohan (CC BY-SA 4.0)

  5. Elastic search, multiple indexes vs one index and types for different data sets?

    There are different implications to both approaches.

    Assuming you are using Elasticsearch's default settings, having 1 index for each model will significantly increase the number of your shards as 1 index will use 5 shards, 5 data models will use 25 shards; while having 5 object types in 1 index is still going to use 5 shards.

    Implications for having each data model as index:

    • Efficient and fast to search within index, as amount of data should be smaller in each shard since it is distributed to different indices.
    • Searching a combination of data models from 2 or more indices is going to generate overhead, because the query will have to be sent to more shards across indices, compiled and sent back to the user.
    • Not recommended if your data set is small since you will incur more storage with each additional shard being created and the performance gain is marginal.
    • Recommended if your data set is big and your queries are taking a long time to process, since dedicated shards are storing your specific data and it will be easier for Elasticsearch to process.

    Implications for having each data model as an object type within an index:

    • More data will be stored within the 5 shards of an index, which means there is lesser overhead issues when you query across different data models but your shard size will be significantly bigger.
    • More data within the shards is going to take a longer time for Elasticsearch to search through since there are more documents to filter.
    • Not recommended if you know you are going through 1 terabytes of data and you are not distributing your data across different indices or multiple shards in your Elasticsearch mapping.
    • Recommended for small data sets, because you will not waste storage space for marginal performance gain since each shard take up space in your hardware.

    If you are asking what is too much data vs small data? Typically it depends on the processor speed and the RAM of your hardware, the amount of data you store within each variable in your mapping for Elasticsearch and your query requirements; using many facets in your queries is going to slow down your response time significantly. There is no straightforward answer to this and you will have to benchmark according to your needs.

    From Stack Overflow: asked by floriank, answered by Jonathan Moo (CC BY-SA 3.0)

  6. Elasticsearch: Difference between "Term", "Match Phrase", and "Query String"

    term query matches a single term as it is : the value is not analyzed. So, it doesn't have to be lowercased depending on what you have indexed.

    If you provided Bennett at index time and the value is not analyzed, the following query won't return anything :

    {
      "query": {
        "term" : { "user" : "bennett" }
      }
    }
    

    match_phrase query will analyze the input if analyzers are defined for the queried field and find documents matching the following criteria:

    • all the terms must appear in the field
    • they must have the same order as the input value
    • there must not be any intervening terms, i.e. be consecutive (potentially excluding stop-words but this can be complicated)

    For example, if you index the following documents (using standard analyzer for the field foo):

    { "foo":"I just said hello world" }
    { "foo":"Hello world" }
    { "foo":"World Hello" }
    { "foo":"Hello dear world" }
    

    This match_phrase query will only return the first and second documents :

    {
      "query": {
        "match_phrase": {
          "foo": "Hello World"
        }
      }
    }
    

    query_string query search, by default, on a _all field which contains the text of several text fields at once. On top of that, it's parsed and supports some operators (AND/OR...), wildcards and so on (see related syntax).

    As the match_phrase queries, the input is analyzed according to the analyzer set on the queried field.

    Unlike the match_phrase, the terms obtained after analysis don't have to be in the same order, unless the user has used quotes around the input.

    For example, using the same documents as before, this query will return all the documents :

    {
      "query": {
        "query_string": {
          "query": "hello World"
        }
      }
    }
    

    But this query will return the same 2 documents as the match_phrase query :

    {
      "query": {
        "query_string": {
          "query": "\"Hello World\""
        }
      }
    }
    

    There is much more to say about the different options for those queries, please take a look at the related documentation :

    Hope this is clear enough and it will help.

    From Stack Overflow: asked by blee908, answered by ThomasC (CC BY-SA 4.0)

  7. What are some use cases for using Elasticsearch versus standard sql queries?

    There are two primary Elasticsearch use cases:

    1. Text search

    You want Elasticsearch when you're doing a lot of text search, where traditional RDBMS databases are not performing really well (poor configuration, acts as a black-box, poor performance). Elasticsearch is highly customizable, extendable through plugins. You can build robust search without much knowledge quite fast.

    1. Logging and analysis

    Another edge case is that a lot people use Elasticsearch to store logs from various sources (to centralize them), so they can analyze them and make sense out of it. In this case, Kibana becomes handy. It lets you connect to Elasticsearch cluster and create visualisations straight away. For instance, Loggly is built using Elasticsearch and Kibana.

    Keep in mind, that you wouldn't want to use Elasticsearch as your primary data storage. Reasons here: How reliable is ElasticSearch as a primary datastore against factors like write loss, data availability

    Update

    I felt like the second part is no longer edgy, it's actually what Elastic as a company has been doing really well in past year. With current DevOps movement, CI/CD pipelines, increasing amount of metrics from various sources, ELK became a defacto choice for infrastructure monitoring, it's no longer just a distributed RESTful text-search engine. It has an amazing set of products:

    • Logstash (tons of data inputs)
    • Beats
      • Filebeat
      • Metricbeat
      • Packetbeat
      • Winlogbeat
    • Kibana
      • Graph
      • Timelion
    • X-Pack (premium)
      • Alerts
      • Reporting
      • Security
      • Machine Learning
      • Cross data center metrics

    An ecosystem, built by community, is growing around ELK stack that expands current features, few of them worth mentioning:

    • ElastAlert
    • Search Guard

    From Stack Overflow: asked by James-Jesse Drinkard, answered by Evaldas Buinauskas (CC BY-SA 3.0)

  8. Elasticsearch vs Cassandra vs Elasticsearch with Cassandra

    One of our applications uses data that is stored into both Cassandra and ElasticSearch. We use Cassandra to access those records whenever we can, and have data duplicated into query tables designed to adhere to specific application-side requests. For a more liberal search than our query tables can allow, ElasticSearch performs that functionality nicely.

    We have asked that same question (of ourselves)..."Why don't we just get everything from ElastsicSearch?"

    The answer is that ElasticSearch was designed to be a search engine, and not a persistent data store. Sometimes ElasticSearch loses writes. Schema changes are difficult to do in ElasticSearch without blowing everything away and reloading. For that purpose, I have written jobs that are designed to keep ElasticSearch in-sync with our Cassandra cluster. There was also a fairly recent discussion on Quora about this topic, that yielded similar points.

    That being said, ElasticSearch works great as a search engine. And Cassandra works great as a scalable, high-performance datastore. But querying data is different from searching for data. There are times that we need one or the other, and a combination of the two works well for our application. It may (or it may not) work well for yours.

    As for analytics, I have had some success in using the Cassandra Spark connector, to serve more complex OLAP queries.

    Edit 20200421

    I've written a newer answer to a similar question:

    ElasticSearch vs. ElasticSearch+Cassandra

    From Stack Overflow: asked by RaceBase, answered by Aaron (CC BY-SA 4.0)

  9. What is the difference between must and filter in Query DSL in elasticsearch?

    must contributes to the score. In filter, the score of the query is ignored.

    In both must and filter, the clause(query) must appear in matching documents. This is the reason for getting same results.

    You may check this link

    Score

    The relevance score of each document is represented by a positive floating-point number called the _score. The higher the _score, the more relevant the document.

    A query clause generates a _score for each document.

    To know how score is calculated, refer this link

    From Stack Overflow: asked by Krash, answered by Vijay (CC BY-SA 4.0)

  10. Redis Vs RabbitMQ as a data broker/messaging system in between Logstash and elasticsearch

    After evaluating both Redis and RabbitMQ I chose RabbitMQ as our broker for the following reasons:

    1. RabbitMQ allows you to use a built in layer of security by using SSL certificates to encrypt the data that you are sending to the broker and it means that no one will sniff your data and have access to your vital organizational data.
    2. RabbitMQ is a very stable product that can handle large amounts of events per seconds and many connections without being the bottle neck.

    Regarding scaling, RabbitMQ has a built in cluster implementation that you can use in addition to a load balancer in order to implement a redundant broker environment.

    Is my RabbitMQ cluster Active Active or Active Passive?

    Now to the weaker point of using RabbitMQ:

    1. most Logstash shippers do not support RabbitMQ but on the other hand, the best one, named Beaver, has an implementation that will send data to RabbitMQ without a problem.
    2. The implementation that Beaver has with RabbitMQ in its current version is a little slow on performance (for my purposes) and was not able to handle the rate of 3000 events/sec from one server and from time to time the service crashed.
    3. Right now I am working on a fix that will solve the performance problem for RabbitMQ and make the Beaver shipper more stable. The first solution is to add more processes that can run simultaneously and will give the shipper more power. The second solution is to change Beaver to send data to RabbitMQ asynchronously which theoretically should be much faster. I hope that I’ll finish implementing both solutions by the end of this week.

    You can follow the issue here: https://github.com/josegonzalez/python-beaver/issues/323

    And check the pull request here: https://github.com/josegonzalez/python-beaver/pull/324

    If you have more questions feel free to leave a comment.

    From Stack Overflow: asked by Salindaw, answered by Tom Kregenbild (CC BY-SA 4.0)

  11. difference between a field and the field.keyword

    Update : A short answer would be that type: text is analyzed, meaning it is broken up into distinct words when stored, and allows for free-text searches on one or more words in the field. The .keyword field takes the same input and keeps as one large string, meaning it can be aggregated on, and you can use wildcard searches on it. Aggregatable means you can use it in aggregations in elasticsearch, which resembles a sql group by if you are familiar with that. In Kibana you would probably use the .keyword field with aggregations to count distinct values etc.

    Please take a look on this article about text vs. keyword.

    Briefly: since Elasticsearch 5.0 string type was replaced by text and keyword types. Since then when you do not specify explicit mapping, for simple document with string:

    {
      "some_field": "string value"
    }
    

    below dynamic mapping will be created:

    {
      "some_field": {
        "type" "text",
        "fields": {
          "keyword": {
            "type": "keyword",
            "ignore_above": 256
          }
        }
      }
    }
    

    As a consequence, it will both be possible to perform full-text search on some_field, and keyword search and aggregations using the some_field.keyword field.

    I hope this answers your question.

    From Stack Overflow: asked by tomak, answered by Piotr Pradzynski (CC BY-SA 4.0)

  12. elasticsearch match vs term query

    Assuming you are using the Standard Analyzer GET becomes get when stored in the index. The source document will still have the original "GET".

    The match query will apply the same standard analyzer to the search term and will therefore match what is stored in the index. The term query does not apply any analyzers to the search term, so will only look for that exact term in the inverted index.

    To use the term query in your example, change the upper case "GET" to lower case "get" or change your mapping so the request.method field is set to not_analyzed.

    From Stack Overflow: asked by Linlin, answered by Akshay (CC BY-SA 3.0)

  13. Elasticsearch query to return all records

    I think lucene syntax is supported so:

    http://localhost:9200/foo/_search?pretty=true&q=*:*

    size defaults to 10, so you may also need &size=BIGNUMBER to get more than 10 items. (where BIGNUMBER equals a number you believe is bigger than your dataset)

    BUT, elasticsearch documentation suggests for large result sets, using the scan search type.

    EG:

    curl -XGET 'localhost:9200/foo/_search?search_type=scan&scroll=10m&size=50' -d '
    {
        "query" : {
            "match_all" : {}
        }
    }'
    

    and then keep requesting as per the documentation link above suggests.

    EDIT: scan Deprecated in 2.1.0.

    scan does not provide any benefits over a regular scroll request sorted by _doc. link to elastic docs (spotted by @christophe-roussy)

    From Stack Overflow: asked by John Livermore, answered by Steve Casey (CC BY-SA 3.0)

  14. Make elasticsearch only return certain fields?

    Yep, Use a better option source filter. If you're searching with JSON it'll look something like this:

    {
        "_source": ["user", "message", ...],
        "query": ...,
        "size": ...
    }
    

    In ES 2.4 and earlier, you could also use the fields option to the search API:

    {
        "fields": ["user", "message", ...],
        "query": ...,
        "size": ...
    }
    

    This is deprecated in ES 5+. And source filters are more powerful anyway!

    From Stack Overflow: asked by user1199438, answered by kevingessner (CC BY-SA 4.0)

  15. Removing Data From ElasticSearch

    You can delete using cURL or visually using one of the many tools that open source enthusiasts have created for Elasticsearch.

    Using cURL

    curl -XDELETE localhost:9200/index/type/documentID
    

    e.g.

    curl -XDELETE localhost:9200/shop/product/1
    

    You will then receive a reply as to whether this was successful or not. You can delete an entire index or types with an index also, you can delete a type by leaving out the document ID like so -

    curl -XDELETE localhost:9200/shop/product
    

    If you wish to delete an index -

    curl -XDELETE localhost:9200/shop
    

    If you wish to delete more than one index that follows a certain naming convention (note the *, a wildcard), -

    curl -XDELETE localhost:9200/.mar* 
    

    Visually

    There are various tools as mentioned above, I wont list them here but I will link you to one which enables you to get started straight away, located here. This tool is called Cerebro (former KOPF), to connect to your host please click on the logo on top left hand corner and enter the URL of your cluster.

    Once connected you will be able to administer your entire cluster, delete, optimise and tune your cluster.

    From Stack Overflow: asked by user687554, answered by Nathan Smith (CC BY-SA 4.0)

  16. Shards and replicas in Elasticsearch

    I'll try to explain with a real example since the answers and replies you got don't seem to help you.

    When you download Elasticsearch and start it up, you create an Elasticsearch node which tries to join an existing cluster if available or creates a new one. Let's say you created your own new cluster with a single node, the one that you just started up. We have no data, therefore we need to create an index.

    When you create an index (an index is automatically created when you index the first document as well) you can define how many shards it will be composed of. If you don't specify a number it will have the default number of shards: 5 primaries (Note: at the time the question was written and up to version 6.x, the default number of primary shards in each index was 5 but since then, version 7.x and beyond, the default has changed to 1). What does it mean?

    It means that Elasticsearch will create 5 primary shards that will contain your data:

     ____    ____    ____    ____    ____
    | 1  |  | 2  |  | 3  |  | 4  |  | 5  |
    |____|  |____|  |____|  |____|  |____|
    

    Every time you index a document, elasticsearch will decide which primary shard is supposed to hold that document and will index it there. Primary shards are not a copy of the data, they are the data! Having multiple shards does help taking advantage of parallel processing on a single machine, but the whole point is that if we start another elasticsearch instance on the same cluster, the shards will be distributed in an even way over the cluster.

    Node 1 will then hold for example only three shards:

     ____    ____    ____ 
    | 1  |  | 2  |  | 3  |
    |____|  |____|  |____|
    

    Since the remaining two shards have been moved to the newly started node:

     ____    ____
    | 4  |  | 5  |
    |____|  |____|
    

    Why does this happen? Because elasticsearch is a distributed search engine and this way you can make use of multiple nodes/machines to manage big amounts of data.

    Every elasticsearch index is composed of at least one primary shard since that's where the data is stored. Every shard comes at a cost, though, therefore if you have a single node and no foreseeable growth, just stick with a single primary shard.

    Another type of shard is a replica. The default is 1, meaning that every primary shard will be copied to another shard that will contain the same data. Replicas are used to increase search performance and for fail-over. A replica shard is never going to be allocated on the same node where the related primary is (it would pretty much be like putting a backup on the same disk as the original data).

    Back to our example, with 1 replica we'll have the whole index on each node, since 2 replica shards will be allocated on the first node and they will contain exactly the same data as the primary shards on the second node:

     ____    ____    ____    ____    ____
    | 1  |  | 2  |  | 3  |  | 4R |  | 5R |
    |____|  |____|  |____|  |____|  |____|
    

    Same for the second node, which will contain a copy of the primary shards on the first node:

     ____    ____    ____    ____    ____
    | 1R |  | 2R |  | 3R |  | 4  |  | 5  |
    |____|  |____|  |____|  |____|  |____|
    

    With a setup like this, if a node goes down, you still have the whole index. The replica shards will automatically become primaries and the cluster will work properly despite the node failure, as follows:

     ____    ____    ____    ____    ____
    | 1  |  | 2  |  | 3  |  | 4  |  | 5  |
    |____|  |____|  |____|  |____|  |____|
    

    Since you have "number_of_replicas":1, the replicas cannot be assigned anymore as they are never allocated on the same node where their primary is. That's why you'll have 5 unassigned shards, the replicas, and the cluster status will be YELLOW instead of GREEN. No data loss, but it could be better as some shards cannot be assigned.

    As soon as the node that had left is backed up, it'll join the cluster again and the replicas will be assigned again. The existing shard on the second node can be loaded but they need to be synchronized with the other shards, as write operations most likely happened while the node was down. At the end of this operation, the cluster status will become GREEN.

    Hope this clarifies things for you.

    From Stack Overflow: asked by LuckyLuke, answered by javanna (CC BY-SA 4.0)

  17. ElasticSearch, Sphinx, Lucene, Solr, Xapian. Which fits for which usage?

    As the creator of ElasticSearch, maybe I can give you some reasoning on why I went ahead and created it in the first place :).

    Using pure Lucene is challenging. There are many things that you need to take care for if you want it to really perform well, and also, its a library, so no distributed support, it's just an embedded Java library that you need to maintain.

    In terms of Lucene usability, way back when (almost 6 years now), I created Compass. Its aim was to simplify using Lucene and make everyday Lucene simpler. What I came across time and time again is the requirement to be able to have Compass distributed. I started to work on it from within Compass, by integrating with data grid solutions like GigaSpaces, Coherence, and Terracotta, but it's not enough.

    At its core, a distributed Lucene solution needs to be sharded. Also, with the advancement of HTTP and JSON as ubiquitous APIs, it means that a solution that many different systems with different languages can easily be used.

    This is why I went ahead and created ElasticSearch. It has a very advanced distributed model, speaks JSON natively, and exposes many advanced search features, all seamlessly expressed through JSON DSL.

    Solr is also a solution for exposing an indexing/search server over HTTP, but I would argue that ElasticSearch provides a much superior distributed model and ease of use (though currently lacking on some of the search features, but not for long, and in any case, the plan is to get all Compass features into ElasticSearch). Of course, I am biased, since I created ElasticSearch, so you might need to check for yourself.

    As for Sphinx, I have not used it, so I can't comment. What I can refer you is to this thread at Sphinx forum which I think proves the superior distributed model of ElasticSearch.

    Of course, ElasticSearch has many more features than just being distributed. It is actually built with a cloud in mind. You can check the feature list on the site.

    From Stack Overflow: asked by user221209, answered by kimchy (CC BY-SA 4.0)

  18. List all indexes on ElasticSearch server?

    For a concise list of all indices in your cluster, call

    curl http://localhost:9200/_aliases
    

    this will give you a list of indices and their aliases.

    If you want it pretty-printed, add pretty=true:

    curl http://localhost:9200/_aliases?pretty=true
    

    The result will look something like this, if your indices are called old_deuteronomy and mungojerrie:

    {
      "old_deuteronomy" : {
        "aliases" : { }
      },
      "mungojerrie" : {
        "aliases" : {
          "rumpleteazer" : { },
          "that_horrible_cat" : { }
        }
      }
    }
    

    From Stack Overflow: asked by Eva, answered by karmi (CC BY-SA 4.0)

  19. elasticsearch bool query combine must with OR
    • OR is spelled should
    • AND is spelled must
    • NOR is spelled must_not

    Example:

    You want to see all the items that are (round AND (red OR blue)):

        {
            "query": {
                "bool": {
                    "must": [
                        {
                            "term": {"shape": "round"}
                        },
                        {
                            "bool": {
                                "should": [
                                    {"term": {"color": "red"}},
                                    {"term": {"color": "blue"}}
                                ]
                            }
                        }
                    ]
                }
            }
        }
    

    You can also do more complex versions of OR, for example, if you want to match at least 3 out of 5, you can specify 5 options under "should" and set a "minimum_should" of 3.

    Thanks to Glen Thompson and Sebastialonso for finding where my nesting wasn't quite right before.

    Thanks also to Fatmajk for pointing out that "term" becomes a "match" in ElasticSearch Version 6.

    From Stack Overflow: asked by Jesse, answered by Daniel Fackrell (CC BY-SA 4.0)

  20. Elasticsearch: Max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]

    Vivek's answer

    sudo sysctl -w vm.max_map_count=262144
    

    is correct, however, the setting will only last for the duration of the session. If the host reboots, the setting will be reset to the original value.

    If you want to set this permanently, you need to edit /etc/sysctl.conf and set vm.max_map_count = 262144.

    Do not forget to reboot or run sysctl --system

    After reboot, you can verify that the setting is still correct by running sysctl vm.max_map_count

    From Stack Overflow: asked by casibbald, answered by Val (CC BY-SA 4.0)

  21. Show all Elasticsearch aggregation results/buckets and not just 10

    The size param should be a param for the terms query example:

    curl -XPOST "http://localhost:9200/imoveis/_search?pretty=1" -d'
    {
       "size": 0,
       "aggregations": {
          "bairro_count": {
             "terms": {
                "field": "bairro.raw",
                 "size": 10000
             }
          }
       }
    }'
    

    Use size: 0 for ES version 2 and prior.

    Setting size:0 is deprecated in 2.x onwards, due to memory issues inflicted on your cluster with high-cardinality field values. You can read more about it in the github issue here .

    It is recommended to explicitly set reasonable value for size a number between 1 to 2147483647.

    From Stack Overflow: asked by Samuel Rizzo, answered by keety (CC BY-SA 4.0)

  22. Beginner's guide to ElasticSearch

    Edit (April 2015):

    As many have noticed, my old blog is now defunct. Most of my articles were transferred over to the Elastic blog, and can be found by filtering on my name: https://www.elastic.co/blog/author/zachary-tong

    To be perfectly honest, the best source of beginner knowledge is now Elasticsearch - The Definitive Guide written by myself and Clinton Gormley.

    It assumes zero search engine knowledge and explains information retrieval first principals in context of Elasticsearch. While the reference docs are all about finding the precise parameter you need, the Guide is a narrative that discusses problems in search and how to solve them.

    Best of all, the book is OSS and free (unless you want to buy a paper copy, in which case O'Reilly will happily sell you one :) )

    Edit (August 2013):

    Many of my articles have been migrated over to the official Elasticsearch blog, as well as new articles that have not been published on my personal site.

    Original post:

    I've also been frustrated with learning ElasticSearch, having no Lucene/Solr experience. I've been slowly documenting things I've learned at my blog, and have four tutorials written so far:

    So I don't have to keep editing, all future tutorials on my blog can be found under this category link.

    And these are some links that I have bookmarked, because they have been incredibly helpful in one way or another:

    From Stack Overflow: asked by uzyn, answered by Zach (CC BY-SA 3.0)

  23. Delete all documents from index without deleting index

    I believe if you combine the delete by query with a match all it should do what you are looking for, something like this (using your example):

    curl -XDELETE 'http://localhost:9200/twitter/tweet/_query' -d '{
        "query" : { 
            "match_all" : {}
        }
    }'
    

    Or you could just delete the type:

    curl -XDELETE http://localhost:9200/twitter/tweet
    

    Note: XDELETE is deprecated for later versions of ElasticSearch

    From Stack Overflow: asked by Michael Leiss, answered by John Petrone (CC BY-SA 4.0)

  24. ElasticSearch: Unassigned Shards, how to fix?

    By default, Elasticsearch will re-assign shards to nodes dynamically. However, if you've disabled shard allocation (perhaps you did a rolling restart and forgot to re-enable it), you can re-enable shard allocation.

    # v0.90.x and earlier
    curl -XPUT 'localhost:9200/_settings' -d '{
        "index.routing.allocation.disable_allocation": false
    }'
    # v1.0+
    curl -XPUT 'localhost:9200/_cluster/settings' -d '{
        "transient" : {
            "cluster.routing.allocation.enable" : "all"
        }
    }'
    

    Elasticsearch will then reassign shards as normal. This can be slow, consider raising indices.recovery.max_bytes_per_sec and cluster.routing.allocation.node_concurrent_recoveries to speed it up.

    If you're still seeing issues, something else is probably wrong, so look in your Elasticsearch logs for errors. If you see EsRejectedExecutionException your thread pools may be too small.

    Finally, you can explicitly reassign a shard to a node with the reroute API.

    # Suppose shard 4 of index "my-index" is unassigned, so you want to
    # assign it to node search03:
    curl -XPOST 'localhost:9200/_cluster/reroute' -d '{
        "commands": [{
            "allocate": {
                "index": "my-index",
                "shard": 4,
                "node": "search03",
                "allow_primary": 1
            }
        }]
    }'
    

    From Stack Overflow: asked by Spanky, answered by Wilfred Hughes (CC BY-SA 4.0)

Related topics

Where these questions come from

Open-source collections on GitHub, official documentation, a government careers service and the Stack Exchange sites, each used under its own licence. The answers are the authors' own words: we only tidy the layout, leave out pictures, and cut a long answer with a link to the rest. Stack Exchange answers stay under CC BY-SA and name who asked and who answered.