Where developers learn, build, and share. Your source for hands-on demos, cheat sheets, explainers and more.

Global
Building search into a Java music library with plain Lucene, one step at a time. The tracks are indexed. Now we query them. Should "Bob" in a title count for more than "Bob" in an album? Step 1: start with no criteria. Open an IndexSearcher and fetch the first 10 hits. Each hit carries a Lucene doc number, so read the stored id and join back to your beans.
We're building search into a Java music library with plain Lucene, one step at a time. Next up is analysis: what happens to your text before it reaches the index. An analyzer cuts it into tokens, lowercases them and folds the accents away. Step 1: add lucene-analysis-common for ASCIIFoldingFilter. Pin the same version as lucene-core
2
1
2
680
Step 3: filter and exclude. Wrap the text query as MUST. Add a FILTER on genre = Club: 62 → 26 hits. Add a MUST_NOT on keys 4A or 4B: 26 → 23. FILTER and MUST_NOT narrow the results without touching the score. Gotcha: a query with only MUST_NOT matches nothing. When users exclude without typing, add a MatchAllDocsQuery as MUST.
1
270
Step 4: ask Lucene why a track ranked where it did. searcher.explain(query, doc) breaks the BM25 score down per term: boost × idf × tf. On a track with "bob" in both title and album, the title clause adds 10.77 and the album clause 4.08. So yes, the title counts for more. Next: facets, counting what users can click. Code for the series, built by @dadoonet github.com/dadoonet/lucene-s…
223
Most “share chat” links are a secret URL to a frozen copy. Anyone with the link can read it, and nobody can continue it. Shared Agent Builder conversations are live and use the Kibana privileges you already have. No bearer link.
2
2
8
1,358
Stop moving Grafana dashboards by hand Elastic’s tools make dashboard migration a whole lot easier: elastic.co/observability-lab…
1
4
1,267
We're building search into a Java music library with plain Lucene, one step at a time. Next up is analysis: what happens to your text before it reaches the index. An analyzer cuts it into tokens, lowercases them and folds the accents away. Step 1: add lucene-analysis-common for ASCIIFoldingFilter. Pin the same version as lucene-core
Your beans are mapped. Now, who owns the index? Step 1: wrap Directory + IndexWriter in a small class dedicated to your bean. ByteBuffersDirectory for in-memory, FSDirectory to persist
3
10
2,086
Step 2: build the analyzer chain. StandardTokenizer splits the text. LowerCaseFilter lowercases it. ASCIIFoldingFilter turns "François" into "francois". No stemming, so artist names stay intact. No stop words, so "Around The World" stays searchable. Use the same analyzer at index time and query time, or your query terms won't match.
1
2
478
Step 3: the index holds terms, not text. After commit, each term points to the documents that contain it. Look up artist:bob and you get docs 1, 2 and 3. It works like the index at the back of a book: jump to the term, skip the scan. Next: type "Bob" and build the query a real search engine runs. Code for the series, built by @dadoonet github.com/dadoonet/lucene-s…
2
389
📣 Attention #DevRel friends! @elastic are hiring Senior Developer Advocates in NYC, US and Sao Paulo, Brazil. Job specs 👇 . jobs.elastic.co/jobs/marketi… jobs.elastic.co/jobs/marketi… If you are based in these locations and have a background in #DevRel or software engineering, apply!
4
6
582
Your beans are mapped. Now, who owns the index? Step 1: wrap Directory + IndexWriter in a small class dedicated to your bean. ByteBuffersDirectory for in-memory, FSDirectory to persist
Get any Java bean ready for Lucene in 3 steps You have a Track bean. You need search. Step 1: embed Apache Lucene in-process. One dependency, no native code, no server to run. Elasticsearch does this for you on top of Lucene. Here's what it looks like by hand 👇
3
3
14
3,057
Step 3: edit one row, not the whole index updateDocument deletes by term, then adds, in one call. Key it on the id StringField from part 1. It's never analyzed, so the term matches exactly.
1
2
414
Step 4: close the writer first, then the directory Order matters If request threads share the index, put every mutation behind the same lock. Rule of thumb: upsert or delete for single-row edits, full rebuild for bulk changes. Next: what happens to a token before it reaches the index. Code for the series, built by @dadoonet github.com/dadoonet/lucene-s…
314
Get any Java bean ready for Lucene in 3 steps You have a Track bean. You need search. Step 1: embed Apache Lucene in-process. One dependency, no native code, no server to run. Elasticsearch does this for you on top of Lucene. Here's what it looks like by hand 👇
2
2
16
3,666
Step 3: map your bean to a Lucene Document. Copy only what you need to find it, and always store the id.
1
1
569