In twitter by using lang operator you can search for retrieving tweets from a particular language: For example, the following search will return tweets only in english:
https://twitter.com/search?q=lang:en
Is there a way to achieve this using twitter api, especially using twitter4j. I know there is a language attribute for search but it also requires at least one keyword to make a search, I would like to search by a particular language without giving any keyword query. The following command in java driver returns the following error:
Query searchQuery = new Query() //
.count(resultsPerPage) //
.since(since)//
.lang("en");
400:The request was invalid. An accompanying error message will explain why. This is the status code will be returned during version 1.0 rate limiting(https://dev.twitter.com/pages/rate-limiting). In API v1.1, a request without authentication is considered invalid and you will get this response.
message - Query parameters are missing
code - 25
Cheers
You must pass the same do you use in the twitter search, your query will be like:
new Query("lang:en")
Using twitter4j,
Query query = new Query();
query.setLang("en");
query.setQuery(searchQuery);
Related
Using the Elasticsearch High Level REST Client for Java v7.3
I have a few fields in the schema that look like this:
{
"document_type" : ["Utility", "Credit"]
}
Basically one field could have an array of strings as the value. I not only need to query for a specific document_type, but also a general string query.
I've tried the following code:
QueryBuilder query = QueryBuilders.boolQuery()
.must(QueryBuilders.queryStringQuery(terms))
.filter(QueryBuilders.termQuery("document_type", "Utility"));
...which does not return any results. If I remove the ".filter()" part the query returns fine, but the filter appears to prevent any results from coming back. I'm suspecting it's because document_type is a multi-valued array - maybe I'm wrong though. How would I build a query query all documents for specific terms, but also filter by document_type?
I think, the reason is the wrong query. Consider using the terms query instead of term query. There is also a eqivalent in the java api.
Here is a good overview of the query qsl queries and their eqivalent in the high level rest client: https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/java-rest-high-query-builders.html
I'm currecntly trying to test out some new score functions on my Elasticsearch query but I'm not yielding the results I am expecting.
I found this on their site about explaining queries here
I can run as a curl command but does anyone know how to translate this to use the Java api?
If you're using the ES5 Java API, you can get the explanation like this:
QueryBuilder query = matchAllQuery(); // your query
ExplainRequest request = new ExplainRequest("index", "type", "id").query(query);
ExplainResponse explainResponse = client.explain(request).actionGet();
Explanation explanation = explainResponse.getExplanation();
Where client is your org.elasticsearch.client.Client instance.
I want to make a query to Google contacts that retrieves all NEW contacts since a given Date.
I am using google contacts api with the following scope: https://www.google.com/m8/feeds/
When I try to make a query that contains publishedMin parameter:
URL feedUrl = new URL("https://www.google.com/m8/feeds/contacts/default/full");
Query myQuery = new Query(feedUrl);
myQuery.setPublishedMin(startDateTime);
myQuery.setMaxResults(1000);
ContactFeed resultFeed = service.getFeed(myQuery, ContactFeed.class);
I get the following error:
com.google.gdata.util.ServiceForbiddenException: Forbidden
This service does not support the 'published-min' parameter.
at com.google.gdata.client.http.HttpGDataRequest.handleErrorResponse(HttpGDataRequest.java:605)
at com.google.gdata.client.http.GoogleGDataRequest.handleErrorResponse(GoogleGDataRequest.java:564)
at com.google.gdata.client.http.HttpGDataRequest.checkResponse(HttpGDataRequest.java:560)
at com.google.gdata.client.http.HttpGDataRequest.execute(HttpGDataRequest.java:538)
at com.google.gdata.client.http.GoogleGDataRequest.execute(GoogleGDataRequest.java:536)
at com.google.gdata.client.Service.getFeed(Service.java:1135)
at com.google.gdata.client.Service.getFeed(Service.java:1077)
How else can I get the new contacts since a given date if I cannot use publishedMin.
Is there an alternative or a workaround for this?
I tried using updatedMin and then search every contact for getPublished() to filter them out but all the values are null.
Thanks in advance.
The Google Contacts API does not support a "published-min" parameter. Out of curiosity, where did you find this Java library that is still trying to use it? (if it is the latest version of a Google-provided library then it ought to be updated)
In the mean time, what you are looking for is the updated-min parameter:
https://developers.google.com/google-apps/contacts/v3/#retrieving_contacts_using_query_parameters
I was trying to implement the feature of template query. Refer to the last section of http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-template.html
I added a query template using sense. Now the need is through JAVA API of elasticsearch, I need to execute this query template and store the result in SearchResponse. However I am not able to find any API related to query Template. The only class file which is available is TemplateQueryBuilder. This class constructs the template query perfectly but I am not sure of which method to be called from Client in order to pass the object of TemplateQueryBuilder.
Help in this is appreciated.
Here is how to do it :
SearchRequestBuilder request = client;.prepareSearch();
request.setTemplateName(templateName);
request.setTemplateType(ScriptService.ScriptType.INDEXED);
request.setTemplateParams(templateParams);
SearchResponse response = request.get();
You just need to parse the response object then ..
refer to: http://www.elasticsearch.org/guide/en/elasticsearch/client/java-api/current/search.html#java-search-template
Note that with API version 2.X, as request.setTemplateX methods are deprecated, you should use a different approach.
Either you can use request.setTemplate(Template template) which is similar to the accepted answer, or you can go with the more generic QueryBuilders approach:
QueryBuilder qb = QueryBuilders.templateQuery(
"templateName",
ScriptService.ScriptType.FILE,
templateParams);
More to read: https://www.elastic.co/guide/en/elasticsearch/client/java-api/2.4/java-specialized-queries.html#java-query-dsl-template-query
new poster here, I found this previous post but it's on C#,
I tried doing this query straight into the java code of a JSP page, for some reason, it doesn't accept the info in the {} of the find() query and just gives out an error...
So peeps, how do I do this in Java:
// retrieve ssn field for documents where last_name == 'Smith':
db.users.find({last_name: 'Smith'}, {'ssn': 1});
Thanks!
PS: why the hell does C# have the nice little .Exclude() and .Include() commands and java doesn't? cries
The java driver follows the exact same API as the shell. Just pass a DBObject containing your field projection as the second argument to find or findOne
As far as I know the official C# driver doesn't expose Include() and Exclude() methods as they violate the standard API.