MongoDB全文搜索索引:错误:文本索引太多,为什么? [英] MongoDB full text search index: error: too many text index for, why?

查看:128
本文介绍了MongoDB全文搜索索引:错误:文本索引太多,为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题,我有收藏,我想将文本搜索索引设置为2个字段(描述和标题)。但是,当我添加第二个索引时,出现以下错误,文本搜索停止工作。

  {serverUsed:localhost / 127.0。 0.1:27017,ok:0.0,errmsg:testdb.users太多文本索引} 

当我删除一个索引搜索时再次开始工作。问题是什么?一个集合仅支持一个字段的全文搜索索引?



我在windows下使用mongodb的当前版本,并使用mongodb的java驱动程序API。

谢谢

解决方案

MongoDB只允许为每个集合提供一个文本索引。

但您可以使用跨越多个字段的文本索引:

  db.collection.ensureIndex({
description: text,
title:text
});

这样,当您正在搜索的短语被找到时,您将得到结果。当这不是你想要的,比如当你有两个搜索查询,每个搜索查询返回一个域的结果而不是另一个域的结果时,你有两个选择。


  1. 使用多字段文本索引,但丢弃来自应用程序层错误字段的结果。
  2. 将两个字段中的一个提取到不同的字段采集。该集合中的文档可能包含完整副本,编辑过的副本或者仅包含索引字段和原始文档的 _id

  3. ol>

    I have one problem, I have collection and I want to set text search index to 2 fields(description and title). But when I add second index I get following error and text search stopped working.

    { "serverUsed" : "localhost/127.0.0.1:27017" , "ok" : 0.0 , "errmsg" : "too many text index for: testdb.users"}
    

    when I delete one index search start work again. what is the problem? One collections support full text search index only for one field????

    I am using the current version of mongodb under windows and I am using mongodb java driver API.

    Thanks

    解决方案

    MongoDB only allows one text-index per collection.

    But you can use a text-index which spans multiple fields:

    db.collection.ensureIndex( {
        description: "text",
        title: "text"
    } );
    

    That way you will get results when the phrase you are searching for is found in either. When this is not what you want, like when you have two search-queries which each return results from one of the fields but not the other, you have two options.

    1. use a multi-field text index, but discard the results which come from the wrong field on the application layer.
    2. extract one of the two fields to a different collection. The documents in that collection could either contain full copies, redacted copies or just the field you index and the _id of the original document.

    这篇关于MongoDB全文搜索索引:错误:文本索引太多,为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆