Records not getting retrieved in case of indexed array. #3999
Replies: 6 comments
-
Hi, I updated your comment for better readability of the json source. Please use code blocks. Your query isn't using your index, which is shown: "index": {
"ddoc": null,
"name": "_all_docs",
"type": "special",
"def": {
"fields": [{
"_id": "asc"
}]
}
}, It's using the Did you try to explicitly use |
Beta Was this translation helpful? Give feedback.
-
Yeah.. that is the problem.. even when i use use_index in my query it is not picking my index and always using _all_docs. Not sure what is the probelm. |
Beta Was this translation helpful? Give feedback.
-
@shrikantgarg17 array elements are not indexed independently when using a As a solution, you can either use a view directly and emit each element in the index as a key, or add the search plugin and use the The view solution would be a map function like:
and then all the view using |
Beta Was this translation helpful? Give feedback.
-
I think the answer is much simpler: There is a special default index only for {
"total_rows": 2,
"indexes": [
{
"ddoc": null,
"name": "_all_docs",
"type": "special",
"def": { "fields": [{ "_id": "asc" }] }
},
{
"ddoc": "_design/c3f8e5d6df2ef807ee1016949098ac4e6287d31c",
"name": "tags-json-index",
"type": "json",
"partitioned": false,
"def": { "fields": [{ "_id": "asc" }, { "shri": "asc" }] }
}
]
} If I only sort for "sort" : ["_id", "shri"] in the query, with the following ddoc {
"_id": "_design/c3f8e5d6df2ef807ee1016949098ac4e6287d31c",
"_rev": "3-bbb25abe2218156af2ad8a5d6648ce1d",
"language": "query",
"views": {
"tags-json-index": {
"map": {
"fields": {
"_id": "asc",
"shri": "asc"
},
"partial_filter_selector": {}
},
"reduce": "_count",
"options": {
"def": {
"fields": [
"_id",
"shri"
]
}
}
}
}
} then the the mango query uses this index... {
"dbname": "test",
"index": {
"ddoc": "_design/c3f8e5d6df2ef807ee1016949098ac4e6287d31c",
"name": "tags-json-index",
"type": "json",
"partitioned": false,
"def": {
"fields": [
{
"_id": "asc"
},
{
"shri": "asc"
}
]
}
},
"partitioned": false,
"selector": {
"$and": [
{
"shri.tags": {
"$elemMatch": {
"": {
"$eq": "java"
}
}
}
},
{
"_id": {
"$gte": "0"
}
}
]
},
"opts": {
"use_index": [],
"bookmark": "nil",
"limit": 501,
"skip": 0,
"sort": {
"_id": "asc",
"shri": "asc"
},
"fields": [
"_id"
],
"partition": "",
"r": [
49
],
"conflicts": false,
"stale": false,
"update": true,
"stable": false,
"execution_stats": false
},
"limit": 501,
"skip": 0,
"fields": [
"_id"
],
"mrargs": {
"include_docs": true,
"view_type": "map",
"reduce": false,
"partition": null,
"start_key": [
"0"
],
"end_key": [
"<MAX>"
],
"direction": "fwd",
"stable": false,
"update": true,
"conflicts": "undefined"
}
} But you are right, with your view function, you have the possibility to use a dynamic query for the tag... |
Beta Was this translation helpful? Give feedback.
-
Moving to discussions... |
Beta Was this translation helpful? Give feedback.
-
ah I'd forgotten about the To add the sort requirement to the view, you would need to add the
and then query the view for all docs containing |
Beta Was this translation helpful? Give feedback.
-
Hi Team,
We are facing issues while retrieving records from an indexed array. though we are not sure if indexing is wrong or querying is wrong but it is taking lot of time to get data.
We are using Couch DB. Here are the details.
We are storing our records in one database whose structure is like this
so i want to have index on tags attribute which is an array. below are the index which i have created
and my selector query is :
but my query takes lot of time. Not sure if indexing is working properly or not.
Below is snippet when i explain my query:
Can anyone please help me on this.
Thanks
Beta Was this translation helpful? Give feedback.
All reactions