简体   繁体   English

在Resheart中查询文档(文本搜索)

[英]Query documents (text search) in Restheart

I created a collection and indexed the field as "text" in mondo shell.我创建了一个集合并将该字段索引为 mondo shell 中的“文本”。 Then I query documents with the following parameters:然后我使用以下参数查询文档:

localhost:8080/db/tags?filter={"$text":{"$search":"some text"}}

and get error:并得到错误:

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"

But in mongo shell everything is OK.但是在 mongo shell 中一切正常。 I got the rigth response on this query:我对这个查询得到了正确的回应:

db.tags.find({"$text":{"$search":"some text"}})

What's wrong?怎么了? I did everything by these tutorials:我通过这些教程做了一切:

https://docs.mongodb.com/manual/reference/operator/query/text/#text-query-examples https://docs.mongodb.com/manual/reference/operator/query/text/#text-query-examples

https://softinstigate.atlassian.net/wiki/spaces/RH/pages/10747996/Query+Documents#QueryDocuments-filteringFiltering https://softinstigate.atlassian.net/wiki/spaces/RH/pages/10747996/Query+Documents#QueryDocuments-filteringFiltering

I'd suggest to re-create the index with RESTHeart instead of Mongo shell.我建议使用 RESTHeart 而不是 Mongo shell 重新创建索引。

First, delete the index with the shell, then create it again by following the examples at: https://restheart.org/learn/indexes/首先,使用 shell 删除索引,然后按照以下示例重新创建它: https : //restheart.org/learn/indexes/

For example, you can create a named index for the collection tags with the following:例如,您可以使用以下内容为集合tags创建命名索引:

PUT /db/tags/_indexes/<index_id> {"keys": {"title": "text" }}

HTTP/1.1 201 Created

Then please let us know if it works.然后请让我们知道它是否有效。

Updated :更新

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):这是我在 RESTHeart 上成功测试全文搜索所做的工作(顺便说一句,我使用的是 httpie 客户端,但 curl 的工作方式类似):

  1. cd into RESTHeart folder cd 到 RESTHeart 文件夹
  2. start dockerized RESTHeart with docker-compose up使用 docker docker-compose up启动 dockerized RESTHeart

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 POST 示例文档

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创建一个名为“about”的集合索引,它使用 JSON 文档中的“about”元素进行文本索引和搜索

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.您将在附件中找到sample.json.zip文件。

I'd suggest to compare the above steps with what you are doing and see if there are remarkable differences.我建议将上述步骤与您正在做的事情进行比较,看看是否存在显着差异。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM