YANG-DB › Examples › Search + graph

Search for it, then follow the graph.

OpenSearch finds documents by their words. YANG-DB follows relationships between them. Together, one query can find the guilds that mention a word, then their members, then the dragons those members own. The data and the search stay on the same cluster.

17use cases
4full-text filters
4string operators
2hops from a search
Step 1 · Connect

Run the searches on your own engine.

The page uses the Dragons tutorial data. It calls YANG-DB's REST API from your browser. Without an engine it shows results recorded from a real one, marked recorded.

Your engine

  • The engine answers at /health
  • The Dragons ontology is registered
  • The Person index has data

If your browser blocks the request (Safari blocks http:// from an https:// page), open a local copy: docs/examples/search/index.html in a clone of the repository.

Start it and load the data

  1. Start YANG-DB and OpenSearch with Docker:
    cd docker && ./buildDocker.sh Dragons
    docker compose -f docker-compose-os.yml up -d
  2. Load the Dragons data. Connect first, then:
    or python3 docker/e2e/load_tutorial.py --reset
  3. Connect on the left. The full-text filters and the string operators below need YANG-DB 0.13.0 or later. Earlier versions get several of them wrong (KNOWN_ISSUES Q27–Q32).
Step 2 · Two kinds of text filter

Search for words, or match part of a value.

A text property is stored twice in OpenSearch. The analysed field holds the value split into lower-cased words, for search. The keyword sub-field holds the value exactly as written. Each filter uses the field that gives it its meaning.

FilterFindsFieldCaseUp to 0.12Cypher, from 0.13
matchany of the wordsanalysedignoredV1search.match(x.p, '…')
match_phrasethe words together, in orderanalysedignoredV1search.match_phrase(x.p, '…')
query_stringLucene syntax: AND OR NOT "…" *analysedignoredV1search.query_string(x.p, '…')
fuzzy eqa word, allowing typosanalysedignoredV1search.fuzzy(x.p, '…')
CONTAINSthe text anywhere in the valuekeywordexactCypher, V1 containsno change
STARTS WITHthe value's beginningkeywordexactCypher, V1 starts withno change
ENDS WITHthe value's endkeywordexactCypher, V1 ends withno change
=~a pattern over the whole valuekeywordexactCypher, V1 likeno change

Every filter works at every position of a pattern: on the node you start from, on the far end of a hop, or several hops away. The planner picks where to start. A filter on a hop's target can be answered from a copy of the field stored on the relationship, so map the copy like the original. The negated forms are in V1 (not match, not contains, fuzzy ne, …). In Cypher, NOT negates a single condition: WHERE NOT d.name CONTAINS 'rax', WHERE NOT search.match(g.description, 'tenetur') (from 0.13; before, Cypher ignored it, Q33).

The data

What there is to search.

The Dragons ontology. Properties of type text can be searched by word. The use cases search guild descriptions (short sentences), and the names of people and dragons. Click a type to see its properties.

Click a node or an arrow · drag to move
Step 3 · Use cases

Search, then follow the relationships.

Every case is Cypher. The full-text ones use the search functions of YANG-DB 0.13 (search.match, search.match_phrase, search.query_string, search.fuzzy); on 0.12, use the V1 operators in the table above. CI checks every case on every pull request, against answers computed by OpenSearch itself.

S1V1

Step 4 · Coming next

Where search + graph is heading.

Planned, not available yet. The IDs refer to the roadmap.

F34.4 · F17

Order by relevance

Order rows by how well the text matched, as OpenSearch scores it, for example the members of the guilds that match best.

… ORDER BY search.score(g) DESC
F16

Similar meaning, then expand

Semantic search: find entities whose embedding is close to a query vector with OpenSearch k-NN, then follow their relationships (the retrieval step of GraphRAG).

WHERE knn(d.embedding, $v, 10)
F29

Search inside a neighbourhood

Run a text, vector or aggregation query only over what a pattern reached, such as the descriptions of the guilds a person's friends belong to.

F34.3

A tutorial and more data

A step-by-step tutorial built on this page, and the same use cases on the traces example: span names and attributes.