SoftInstigate / restheart

Rapid API Development with MongoDB
https://restheart.org
GNU Affero General Public License v3.0
805 stars 171 forks source link

500 Error when filtering with parameters: "$text" and "$search" #314

Closed StrozhDima closed 6 years ago

StrozhDima commented 6 years ago

Getting 500 error with using text search operators.

Expected Behavior

I should get response with some entries

Current Behavior

I got 500 error with the following context: {"http status code":500,"http status description":"Internal Server Error","message":"Query failed with error code 2 and error message 'Too many text expressions' on server 127.0.0.1:27017"}

Context

I checked the same request in mongo shell and got the correct answer.

Environment

Operating System: Linux Ubuntu 18.04 RESTHeart version: 3.4.2 MongoDB version: 3.6.3 restheart.yml.zip

Steps to Reproduce

1.create collection and indexes in mongo shell 2.create some entries in the collection using restheart api 3.try to query documents using text search operators

Possible Implementation

I got the following log in mongo:

2018-09-18T16:00:23.783+0300 I COMMAND [conn2] command story-db.tags command: find { find: "tags", filter: { $and: [ { $text: { $search: "like" } }, { $text: { $search: "like" } } ] }, sort: { _id: -1 }, batchSize: 1000, $db: "story-db", lsid: { id: UUID("81b3d72f-b885-414b-a5ac-c7826a6b2d90") }, $readPreference: { mode: "primaryPreferred" } } numYields:0 reslen:93 locks:{ Global: { acquireCount: { r: 6 } }, Database: { acquireCount: { r: 3 } }, Collection: { acquireCount: { r: 2 } } } protocol:op_msg 0ms

mkjsix commented 6 years ago

Hi @StrozhDima

Could you please specify the querystring parameter that you are using to invoke RESTHeart?

StrozhDima commented 6 years ago

Hi @mkjsix There is the description of the issue: https://stackoverflow.com/questions/52387898/query-documents-text-search-in-restheart

mkjsix commented 6 years ago

Ok thanks, we'll follow-up there

mkjsix commented 6 years ago

This functionality is basic and it's working since years now, I cannot reproduce the problem. Here what I did to successfully test a full text search on RESTHeart (BTW I'm using the httpie client, but curl would work similarly):

  1. cd into RESTHeart folder
  2. start dockerized RESTHeart with docker-compose up

Then issue the following commands:

Creare a db http -a admin:changeit PUT http://localhost:8080/mydb

Create a collection http -a admin:changeit PUT http://localhost:8080/mydb/sample

POST sample documents http -a admin:changeit POST http://localhost:8080/mydb/sample < sample.json

Create a collection index named "about" which uses the "about" element in JSON documents for text indexing and searching http -j -a admin:changeit PUT http://localhost:8080/mydb/sample/_indexes/about keys:='{"about":"text"}}'

Check the index http -a admin:changeit GET http://localhost:8080/mydb/sample/_indexes

Perform successful full text search: http -a admin:changeit GET http://localhost:8080/mydb/sample?filter='{"$text":{"$search":"\"Consequat fugiat commodo irure\""}}'

HTTP/1.1 200 OK
Access-Control-Allow-Credentials: true
Access-Control-Allow-Origin: *
Access-Control-Expose-Headers: Location, ETag, Auth-Token, Auth-Token-Valid-Until, Auth-Token-Location, X-Powered-By
Auth-Token: 240ym6d4sbxujjl8qa0ezslyfcpx7tmrjo4lfqmcxx9uirjjcs
Auth-Token-Location: /_authtokens/admin
Auth-Token-Valid-Until: 2018-09-19T07:46:37.717Z
Connection: keep-alive
Content-Encoding: gzip
Content-Length: 793
Content-Type: application/json
Date: Wed, 19 Sep 2018 07:31:37 GMT
ETag: 5ba11d9aa7b11b0006d54c5f
X-Powered-By: restheart.org

{
    "_embedded": [
        {
            "_etag": {
                "$oid": "5ba11db6a7b11b0006d54c61"
            }, 
            "_id": "5ba11d3ffb91c9eb48eee9f2", 
            "about": "Nulla pariatur eu dolor ad fugiat cillum. Ex consectetur id velit officia veniam pariatur nisi ea et nisi aliquip reprehenderit adipisicing incididunt. Exercitation esse mollit in pariatur eiusmod veniam quis est consequat ad. Fugiat eu excepteur fugiat incididunt et. Consequat fugiat commodo irure id magna in magna minim non anim amet. Officia ipsum veniam excepteur consequat labore.", 
            "address": "923 Sheffield Avenue, Wescosville, California, 2455", 
            "age": 20, 
            "balance": "$1,335.75", 
            "company": "FLEXIGEN", 
            "email": "terra.gross@flexigen.name", 
            "eyeColor": "blue", 
            "favoriteFruit": "strawberry", 
            "friends": [
                {
                    "id": 0, 
                    "name": "May Rowland"
                }, 
                {
                    "id": 1, 
                    "name": "Schmidt Herman"
                }, 
                {
                    "id": 2, 
                    "name": "Saundra Shepard"
                }
            ], 
            "greeting": "Hello, Terra! You have 6 unread messages.", 
            "guid": "c529609b-8535-4aea-a386-d3861e3fe831", 
            "index": 3, 
            "isActive": false, 
            "latitude": "-43.467295", 
            "longitude": "114.929505", 
            "name": {
                "first": "Terra", 
                "last": "Gross"
            }, 
            "phone": "+1 (956) 474-2649", 
            "picture": "http://placehold.it/32x32", 
            "range": [
                0, 
                1, 
                2, 
                3, 
                4, 
                5, 
                6, 
                7, 
                8, 
                9
            ], 
            "registered": "Saturday, February 17, 2018 1:13 PM", 
            "tags": [
                "excepteur", 
                "velit", 
                "sint", 
                "sit", 
                "eu"
            ]
        }
    ], 
    "_etag": {
        "$oid": "5ba11d9aa7b11b0006d54c5f"
    }, 
    "_id": "sample", 
    "_returned": 1
}

You'll find the sample.json.zip file in attachment.

I'd suggest to compare the above steps with what you are doing and see if there are remarkable differences.

StrozhDima commented 6 years ago

@mkjsix I've done it. And it works!

mkjsix commented 6 years ago

Glad it works now! I'm closing the issue, but feel free to reopen it in case of any further question.

StrozhDima commented 6 years ago

@mkjsix ok.

StrozhDima commented 6 years ago

@mkjsix Hi. I didn't solve my problem. I When I create indexes first, and then add entries to the collection, the error appears again.

ujibang commented 6 years ago

@StrozhDima can you please detail how you create the index? thanks

StrozhDima commented 6 years ago

@mkjsix

echo "Creating collection $DB_TAGS_COLLECTION in database $DB ..." | tee -a init_database.log curl -XPUT $SERVER/$LOCATION/$DB/$DB_TAGS_COLLECTION -w "\n" | tee -a init_database.log echo "Creating indexes in collection $DB_TAGS_COLLECTION ..." | tee -a init_database.log

curl -H 'Content-Type: application/json' -XPUT -d '{"keys":{"text":"text"}}' $SERVER/$LOCATION/$DB/$DB_TAGS_COLLECTION/_indexes/text | tee -a init_database.log

echo "End creating collection $DB_TAGS_COLLECTION." | tee -a init_database.log