[英]Importing sql data into solr using the data handler called from C#
I'm trying to call the data import handler in solr to import records from sql into a solr collection, I've got the request the ui sends from fiddler, and I am using the same request in my c# application, however the request does not import the data. 我正在尝试在solr中调用数据导入处理程序以将sql中的记录导入到solr集合中,我已经收到ui从提琴手发送的请求,并且我在c#应用程序中使用了相同的请求,但是该请求确实不导入数据。 Can anyone help me get this working? 谁能帮我解决这个问题?
public class SolrRequest
{
public string SendPostRequest(string requestType, string dataToPost, string requestInfo, string pathOfRequest)
{
LocalhostSet.LocalhostSet solrlocalhost = new LocalhostSet.LocalhostSet();
string hasSuccess = "";
string localhostSet = "";
localhostSet = solrlocalhost.setLocalHost(localhostSet);
string URI = "http://localhost:8999/solr/new_core/dataimport" ;
string myParameters = "full-import&clean=true&commit=true&wt=json&indent=true&entity=holidays&rows=10000000&verbose=false&optimize=false&debug=false";
using (WebClient wc = new WebClient())
{
wc.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
string HtmlResult = wc.UploadString(URI, myParameters);
}
try
{
Console.WriteLine(requestInfo);
var request = HttpWebRequest.Create(localhostSet);
request.Method = requestType;
request.ContentType = "application/x-www-form-urlencoded";
if (requestType.Equals("PUT") | requestType.Equals("POST"))
{
using (var writer = new StreamWriter(request.GetRequestStream()))
{
writer.Write(dataToPost);
}
}
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
hasSuccess = "Request Successful";
string status = response.StatusDescription.ToString();
if (requestType.Equals("GET"))
{
StreamReader reader = new StreamReader(response.GetResponseStream());
string tmp = reader.ReadToEnd();
}
}
catch (WebException webex)
{
WebResponse errResp = webex.Response;
using (Stream respStream = errResp.GetResponseStream())
{
StreamReader reader = new StreamReader(respStream);
string text = reader.ReadToEnd();
}
hasSuccess = "Request Unsuccessful";
}
Console.WriteLine(hasSuccess);
return hasSuccess;
}
The url was wrong, the url should reference the collection in this case "new_core" 网址错误,在这种情况下,网址应引用集合“ new_core”
http://localhost:8999/solr/new_core/dataimport?command=full-import http:// localhost:8999 / solr / new_core / dataimport?command = full-import
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.