使用 HTTP POST 时 Solr 查询字符串是否有大小或期限限制? [英] Is there a size or term limit for a Solr query string when using HTTP POST?

查看:31
本文介绍了使用 HTTP POST 时 Solr 查询字符串是否有大小或期限限制?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Java 查询 Solr 服务器,以获取在我感兴趣的一组已知 ID 中具有 ID 的结果.

I'm using Java to query a Solr server for results that have IDs within a set of known IDs that I am interested in.

我认为要获得我感兴趣的这些结果的最佳方法是创建一个长查询字符串,如下所示:

The best way I could think to get just these results that I am interested in was to create a long query string that looks something like this:

q=(item_id:XXX33-3333 OR item_id:YYY42-3445 OR item_id:JFDE-3838)

我在提出请求之前生成了这个字符串,queryString,并且我最终想要提出的请求中包含超过 1500 个这样的 id.我正在使用 HTTP POST 进行查询:

I generate this String, queryString, before making my request, and there are over 1500 such ids included in the request I would eventually like to make. I am using an HTTP POST to make the query as such:

        HttpPost post = new HttpPost(url);
        post.setHeader("Content-Type", "application/x-www-form-urlencoded; charset=utf-8");

        StringEntity entity = new StringEntity(queryString, "UTF-8");
        entity.setContentType("application/x-www-form-urlencoded; charset=utf-8");
        post.setEntity(entity);

        HttpClient client = new DefaultHttpClient();
        HttpResponse response = client.execute(post);

如果我将查询限制为前 1000 个 ID,它就会成功,并且我会如预期的那样返回结果.但是,如果我增加查询以包含我真正感兴趣的所有 1500,我会收到一个 HTTP 400 响应代码,并显示以下错误:

If I limit the query to just the first 1000 ids, it succeeds and I get the results back as I would expect. However, if I increase the query to include all 1500 that I am really interested in, I get an HTTP 400 response code with the following error:

HTTP/1.1 400 org.apache.lucene.queryParser.ParseException:无法解析[我的查询在这里...]

我可以在 Solr 查询中或"在一起的 ID 数量是否有限制?当我超过 1000 时,这是否还有其他原因可能会失败?我已经尝试过,它在 1024 左右失败(我的 ID 长度几乎相同),所以这似乎表明存在字符或期限限制.

Is there a limit to the number of ids that I can OR together in a Solr query? Is there another reason this might be failing when I go past 1000? I have experimented and it fails at around 1024 (my ids are all almost the same length) so it seems to suggest there is a character or term limit.

或者,如果有人对我如何以另一种更智能的方式检索我正在寻找的项目有很好的建议,我很乐意听到.我的备份解决方案只是查询 Solr 的 all 项目,解析结果,并使用属于我感兴趣的集合的那些.我不想这样做,因为数据源可以有数以万计的项目,这将是低效的.

Or, if someone has a good suggestion of how I can retrieve the items I'm looking for in another, smarter, way, I would love to hear it. My backup solution is just to query Solr for all items, parse the results, and use the ones that belong to the set I am interested in. I would prefer not to do this, since the data source could have tens of thousands of items, and it would be inefficient.

推荐答案

Solr 方面没有限制——我们经常以类似的方式使用 Solr,查询中有数万个 ID.

There is no limit on the Solr side - we regularly use Solr in a similar way with tens of thousands of IDs in the query.

您需要查看 servlet 容器(Tomcat、Jetty 等)的设置并增加最大 POST 大小.如果您使用的是 Tomcat,请查找 maxPostSize,如果您使用的是 Jetty,请查找 maxFormContentSize.

You need to look at the settings for your servlet container (Tomcat, Jetty etc.) and increase the maximum POST size. Look up maxPostSize if you are using Tomcat and maxFormContentSize if you are using Jetty.

这篇关于使用 HTTP POST 时 Solr 查询字符串是否有大小或期限限制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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