简体   繁体   中英

mongodb, full text search instead of multiple fields

I need to query against many fields inside my documents, and I got the idea of instead of having to index (or compound index) the fields I need, to concatenate the relevant data that needs to be searchable inside a single text field in the document and search against it. Bad or good idea?

Possible example with indexes (or compound indexes)

{
    name: "john",
    last: "doe,
    city: "new york",
    likes: ["pizza", "ice cream"],
}

Possible example with a single index on a text field:

{
    name: "john",
    last: "doe,
    city: "new york",
    likes: "pizza",
    search: "john doe new york pizza ice cream",
}

It all depends on your data retrieval pattern from db of your application. If you have a lot of text (paragraphs of text) to be searched, full text search is a good idea. If it is few, better to stick to a array of texts approach.

However, keep in mind that only one full text search field allowed within a single collection.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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