Mango+Nouveau queries and Indexes don’t behave as expected
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 32/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Stale
- Domain
- backend-api-design, databases
Research direction
Reproduce the string, number, and $text cases from the cURL examples, then compare them with the related cases in test/elixir/test/nouveau_test.exs. Read the linked Mango and Nouveau documentation to clarify the intended behavior for string and text fields. Done means the documented expected results are consistent for string queries, Lucene-style $text queries, and text field indexes.
Written by the indexing model from the issue text.
Description
Hello,
I’ve been trying out Mango and Nouveau together, orienting myself along what’s in the docs and the tests, and have run into several problems. I’ve provided a full set of cURL commands to reproduce the issues, namely:
- Queries against
stringindex fields only occasionally work $textqueries work the same as regular queries againststringindex fields: they’re keyword searches, not Lucene full-text searches"type": "text"index fields never seem to work at all
This didn’t become obvious in testing because the tests seem to:
- Use the one of the two
stringindex fields that actually works by sheer coincidence - Use a
$textquery that also worked by coincidence, not because the underlying mechanism works properly
I’ve basically done something similar to the Mango-related tests in this file and linked the relevant lines from the test file below.
Using CouchDB 3.4.2 with nouveau-1.0-SNAPSHOT.jar. For all of these, _explain showed that the correct index was used, unless I’ve stated otherwise.
Setup
Add this line to all requests in case you need auth:
--user COUCHDB_USERNAME:COUCHDB_PASSWORD \
First, make a fresh DB:
curl -X PUT \
'http://127.0.0.1:5984/mouveau' \
--header 'Accept: */*' \
Insert some docs:
curl -X POST \
'http://127.0.0.1:5984/mouveau/_bulk_docs' \
--header 'Accept: */*' \
--header 'Content-Type: application/json' \
--data-raw '
{
"docs": [
{
"_id": "FishStew",
"servings": 4,
"subtitle": "Delicious with freshly baked bread",
"title": "Fish Stew",
"type": "fish"
},
{
"_id": "LambStew",
"servings": 6,
"subtitle": "Serve with a whole meal scone topping",
"title": "Lamb Stew",
"type": "meat"
},
{
"_id": "Dumplings",
"servings": 8,
"subtitle": "Hand-made dumplings make a great accompaniment",
"title": "Dumplings",
"type": "meat"
}
]
}'
Now make a Nouveau index. This is basically the same index as used in the tests but adapted to our documents' field names:
curl -X POST \
'http://127.0.0.1:5984/mouveau/_index' \
--header 'Accept: */*' \
--header 'Content-Type: application/json' \
--data-raw '{
"type": "nouveau",
"index": {
"fields": [
{"name": "title", "type": "string"},
{"name": "servings", "type": "number"},
{"name": "type", "type": "string"}
],
"default_analyzer": "keyword"
}
}'
Let’s do some queries. First, querying for strings, analogous to the Mango search by string test:
curl -X POST \
'http://127.0.0.1:5984/mouveau/_find' \
--header 'Accept: */*' \
--header 'Content-Type: application/json' \
--data-raw '{
"selector": {
"type": "meat"
}
}'
That works.
(Only showing selector lines for brevity from now on, the cURL command is always the same)
"selector": {
"title": "Lamb Stew"
}
This doesn’t work at all:
{
"error": "nouveau_search_error",
"reason": "bad_request: field \"title_3astring\" was indexed without position data; cannot run PhraseQuery (phrase=title_3astring:\"lamb stew\")",
"ref": 2009526893
}
Hm, maybe if we just search for a single word?
"selector": {
"title": "Dumplings"
}
Different nope, but also nope:
{
"docs": [],
"bookmark": "W10="
}
What about numbers? This is analogous to the Mango search by number test:
"selector": {
"servings": {"$gte": 6}
}
That works.
The last test is a $text query, same as the mango search by text test. Now, interestingly, the doc example for this query type selector looks different than the one in the test:
// test: just a keyword
{"$text": "hello"}
// docs: this is Lucene full-text search syntax
{
"_id": { "$gt": null },
"$text": "director:George"
}
Also, remember: the test runs this $text query against an index that does not have any "type":"text" fields! And surprisigly, this works!
"selector": {
"$text": "lamb"
}
But this seems to be only a keyword search, and not a fully-fledged text search, which becomes apparent because these all fail:
"selector": {
"$text": "lamb s"
}
"selector": {
"$text": "title:lamb"
}
"selector": {
"$text": "title:lam*"
}
"selector": {
"$text": "lam*"
}
And all permutations thereof.
Summary:
numberqueries, as in the tests, work. Yay.stringqueries, as in the tests, sometimes work. Couldn’t find a pattern yet.$textqueries against the index as used in the tests do not actually perform Lucene queries, but the same keyword-style searches as thestringqueries, but against all (string?) index fields.
Workaround attempts:
- Change the order of the
stringqueries to see what happens: no change, querying fortitlestill fails,typestill works. - Try different values for
default_analyzerandanalyzer.default, bothstandardandenglishdo not change the results for$textqueries.
What about the text index type?
Now, the test mango index and the example index in the docs are the same, and interestingly, the docs refer to this as a Text index. However, this section also describes a text index field type, just like in Nouveau, to go alongside string and number and boolean index field types. This isn’t documented or tested anywhere, but I’d assume this to work like so (delete the old ddoc first):
curl -X POST \
'http://127.0.0.1:5984/mouveau/_index' \
--header 'Accept: */*' \
--header 'Content-Type: application/json' \
--data-raw '{
"type": "nouveau",
"index": {
"fields": [
{"name": "title", "type": "text"}
],
"default_analyzer": "english"
}
}'
But no query against this returns anything, no permutation of $text works, and using something like "title": "Dumplings" falls back to not using any index.
Expected results:
- Queries against
stringindex fields always work. $textqueries use Lucene syntax? Unsure what the intention is here, the docs do one thing, the tests another.texttype indexes are queryable with a selector like"$text": "fieldname:querystring".
- Dominant language
- Erlang
- Stars
- 7k
- Forks
- 1.1k
- Avg merge
- 1d 23m
- Merged PRs (30d)
- 30
Getting set up
Starts the project's dev container in your browser, under your own GitHub account.
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from apache/couchdb
-
Fix: Warning: 'catch ...' is deprecated; please use 'try ... catch ... end' insteadPossibly taken @devx-arjun claimed this 3 days ago. Openbeginner-friendly build chore patches-welcome
Difficulty 4/5 3-5 days Newbie friendliness 45/100
apache/couchdb#6144 · 4 comments ·
Maintainers usually reply within 1 day
-
bug needs-triage
Difficulty 4/5 3-5 days Newbie friendliness 48/100
apache/couchdb#6132 · 3 comments ·
Maintainers usually reply within 1 day
-
enhancement
Difficulty 5/5 Over a week Newbie friendliness 45/100
apache/couchdb#6120 · 4 comments ·
Maintainers usually reply within 1 day
-
enhancement needs-triage
Difficulty 3/5 1-2 days Newbie friendliness 55/100
Maintainers usually reply within 1 day
-
bug needs-triage
Difficulty 4/5 3-5 days Newbie friendliness 48/100
Maintainers usually reply within 1 day
Similar issues
-
Difficulty 1/5 Under an hour Newbie friendliness 72/100
supadata-ai/mcp#27 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
objectionary/sodg.rs#300 ·
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
topoteretes/cognee#5647 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
components-web-app/api-components-bundle#403 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
mollie/PrestaShop#1566 ·
Maintainers usually reply within 1 day