elasticsearch 弹性搜索和Twitter数据示例
我正在学习弹性搜索,我正在跟随。在该教程中,它使用twitter的tweets作为示例数据。方法tweetJsonList返回一个示例数据。我试图将其保存在“tweets_juan”索引中,然后键入“tweet”。应用程序运行没有问题,但是当我使用(:)搜索所有文档时,我没有找到任何东西。你能帮我核实一下这里发生了什么吗elasticsearch 弹性搜索和Twitter数据示例,elasticsearch,twitter,elasticsearch,Twitter,我正在学习弹性搜索,我正在跟随。在该教程中,它使用twitter的tweets作为示例数据。方法tweetJsonList返回一个示例数据。我试图将其保存在“tweets_juan”索引中,然后键入“tweet”。应用程序运行没有问题,但是当我使用(:)搜索所有文档时,我没有找到任何东西。你能帮我核实一下这里发生了什么吗 public class App { @SuppressWarnings("unchecked") public static void main( String[] arg
public class App
{
@SuppressWarnings("unchecked")
public static void main( String[] args ) throws TwitterException, UnknownHostException
{
System.out.println( "Hello World!" );
List<String> tweetJsonList = searchForTweets();
Client client = TransportClient.builder().build()
.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("localhost"), 9300));
String index = "tweets_juan";
client.admin().indices()
.create(new CreateIndexRequest(index))
.actionGet();
save(client, tweetJsonList, index);
searchExample(client);
}
public static void save(Client client, List<String> tweetJsonList, String index) {
BulkRequestBuilder bulkRequestBuilder = client.prepareBulk().setRefresh(true);
for (String data : tweetJsonList) {
String indexName = index;
String typeName = "tweet";
String json = new Gson().toJson(data);
System.out.println("Juan Debug:" + data);
bulkRequestBuilder.add(client.prepareIndex(indexName, typeName).setSource(json));
}
bulkRequestBuilder.execute().actionGet();
}
public static void searchExample(Client client) {
BoolQueryBuilder queryBuilder = QueryBuilders
.boolQuery()
.must(termsQuery("text", "Baloncesto"));
SearchResponse searchResponse = client.prepareSearch("tweets_juan")
.setQuery(queryBuilder)
.setSize(25)
.execute()
.actionGet();
}
public static List searchForTweets() throws TwitterException {
Twitter twitter = new TwitterFactory().getInstance();
Query query = new Query("mundial baloncesto");
List tweetList = new ArrayList<>();
for (int i = 0; i < 10; i++) {
QueryResult queryResult = twitter.search(query);
tweetList.addAll(queryResult.getTweets());
if (!queryResult.hasNext()) {
break;
}
query = queryResult.nextQuery();
}
Gson gson = new Gson();
return (List) tweetList.stream().map(gson::toJson).collect(Collectors.toList());
}
}
公共类应用程序
{
@抑制警告(“未选中”)
公共静态void main(字符串[]args)抛出TwitterException、UnknownHostException
{
System.out.println(“你好,世界!”);
列出tweetJsonList=searchForTweets();
Client Client=TransportClient.builder().build()
.addTransportAddress(新的InetSocketTransportAddress(InetAddress.getByName(“localhost”),9300));
String index=“tweets_juan”;
client.admin().index()
.create(新建CreateIndexRequest(索引))
.actionGet();
保存(客户端、tweetJsonList、索引);
搜索示例(客户);
}
公共静态void保存(客户端、列表tweetJsonList、字符串索引){
BulkRequestBuilder BulkRequestBuilder=client.prepareBulk().setRefresh(true);
for(字符串数据:tweetJsonList){
字符串indexName=索引;
字符串typeName=“tweet”;
字符串json=new Gson().toJson(数据);
System.out.println(“Juan Debug:+数据”);
add(client.prepareIndex(indexName,typeName).setSource(json));
}
bulkRequestBuilder.execute().actionGet();
}
公共静态无效搜索示例(客户端){
BoolQueryBuilder queryBuilder=QueryBuilders
.boolQuery()
.必须(术语(“文本”、“香榭丽舍”);
SearchResponse SearchResponse=client.prepareSearch(“推特”)
.setQuery(queryBuilder)
.setSize(25)
.execute()
.actionGet();
}
公共静态列表searchForTweets()引发TwitterException{
Twitter=new TwitterFactory().getInstance();
查询=新查询(“mundial baloncesto”);
List tweetList=new ArrayList();
对于(int i=0;i<10;i++){
QueryResult QueryResult=twitter.search(查询);
addAll(queryResult.getTweets());
如果(!queryResult.hasNext()){
打破
}
query=queryResult.nextQuery();
}
Gson Gson=新的Gson();
return(List)tweetList.stream().map(gson::toJson).collect(Collectors.toList());
}
}
在任何人回答您的问题之前,您需要提供更多信息
由于未使用任何显式映射,因此默认情况下必须对字段进行分析。因此,您的文本字段将被标记为多个术语
在任何人回答你的问题之前,你需要提供更多的信息 由于未使用任何显式映射,因此默认情况下必须对字段进行分析。因此,您的文本字段将被标记为多个术语
在搜索中设置类型后尝试搜索:
client.prepareSearch(“tweets_-juan”).setTypes(“tweet”).setQuery(queryBuilder).setSize(25).execute().actionGet()
@ryanlutgen只是我在尝试,但在搜索中设置类型后,我没有得到任何东西try sarching:client.prepareSearch(“tweets_juan”).setTypes(“tweet”).setQuery(queryBuilder).setSize(25).execute().actionGet()代码>@ryanlutgen我只是在尝试,但我什么也没得到