Understanding Typesense with Java and MongoDB
TLDR Vasudev needed help implementing a Java project with Typesense and MongoDB. Kishore Nallan guided them in designing the project, explaining different methods, providing templates, and responding to error issues. At last, Vasudev successfully implemented the project and expressed gratitude.
Jul 21, 2022 (15 months ago)
Vasudev
07:05 AMKishore Nallan
07:16 AMVasudev
07:19 AMVasudev
07:20 AMis it possible to index it into typesense using java
Kishore Nallan
07:21 AMVasudev
07:23 AMKishore Nallan
07:27 AMVasudev
08:29 AMKishore Nallan
08:32 AMVasudev
08:54 AMVasudev
09:31 AMSearchParameters searchParameters = new SearchParameters()
.q("harry")
.addQueryByItem("title")
.addSortByItem("ratings_count:desc");
addQueryByItem is not defined
Vasudev
09:32 AMSearchParameters searchParameters = new SearchParameters()
.q("tokoyo") .addQueryByItem("countryName").addQueryByItem("capital") .addPrefixItem(true).addPrefixItem(false);
SearchResult searchResult = client.collections("countries").documents().search(searchParameters);
Vasudev
09:33 AMKishore Nallan
10:29 AMVasudev
10:44 AMpackage org.typesense.Client;
import org.typesense.api.*;
import org.typesense.model.*;
import org.typesense.resources.*;
import java.nio.file.Files;
import java.nio.file.Path;
import java.time.Duration;
import java.util.ArrayList;
public class Indexing {
public void newClient() throws Exception {
ArrayList<Node> nodes = new ArrayList<>();
nodes.add(
new Node(
"http",
"localhost",
"8108"
)
);
Configuration configuration = new Configuration(nodes, Duration.ofSeconds(2),"MyAPI");
Client client = new Client(configuration);
CollectionSchema collectionSchema = new CollectionSchema();
collectionSchema.name("books").defaultSortingField("ratings_count")
.addFieldsItem(new Field().name("title").type("string"))
.addFieldsItem(new Field().name("authors").type("string[]").facet(true))
.addFieldsItem(new Field().name("publication_year").type("string").facet(true))
.addFieldsItem(new Field().name("ratings_count").type("int32"))
.addFieldsItem(new Field().name("average_rating").type("float"));
CollectionResponse collectionResponse = client.collections().create(collectionSchema);
String booksData = Files.readString(Path.of("org/typesense/Data/books.jsonl"));
client.collections("books").documents().import_(booksData);
System.out.println(booksData);
SearchParameters searchParameters = new SearchParameters()
.q("harry")
.queryBy("title");
SearchResult searchResult = client.collections("books").documents().search(searchParameters);
System.out.println(searchResult);
}
}
Vasudev
10:45 AMVasudev
10:46 AMVasudev
10:47 AMpackage org.typesense;
import org.typesense.Client.Indexing;
public class Main {
public static void main(String[] args) throws Exception {
Indexing i=new Indexing();
i.newClient();
}
}
Kishore Nallan
10:47 AMVasudev
11:16 AMVasudev
11:33 AMx-typesense-api-key
header must be sent."this error is shown
while i have inserted my API key in node configuration
Vasudev
12:15 PMcollection already exist
so is there any method in java to delete collection before reading the json data like i have done in javascript:-
Vasudev
12:15 PMawait typesense.collections('books').delete();
console.log('Deleting existing collection: books');
} catch (error) {
// Do nothing
}
Kishore Nallan
12:29 PMVasudev
01:27 PMVasudev
01:27 PMKishore Nallan
02:12 PMJul 22, 2022 (15 months ago)
Vasudev
06:38 AMVasudev
06:38 AMVasudev
06:39 AMi can use typesense in springboot ?
Kishore Nallan
06:41 AMVasudev
06:45 AMKishore Nallan
06:50 AMVasudev
06:57 AMJul 24, 2022 (15 months ago)
Vasudev
09:51 AMfacetCounts: []
found: 0
searchTimeMs: 0
outOf: 0
searchCutoff: false
page: 1
groupedHits: null
hits: []
requestParams: class SearchResultRequestParams {
collectionName: books
q: harry
perPage: 10
}
}
Vasudev
09:52 AMKishore Nallan
10:00 AMVasudev
10:03 AMVasudev
10:03 AMVasudev
10:08 AMVasudev
10:08 AMKishore Nallan
10:10 AMJul 25, 2022 (15 months ago)
Vasudev
12:18 PMi have gone through whole documentation for mongoDB to TypeSense, want to know that https://github.com/HarisaranG/typesense-mongodb
this link will convert directly or it is just a template to start?
Kishore Nallan
12:23 PMIt will help sync data.
Vasudev
12:25 PMTypesense
Indexed 2779 threads (79% resolved)
Similar Threads
Troubleshooting Typesense Document Import Error
Christopher had trouble importing 2.1M documents into Typesense due to memory errors. Jason clarified the system requirements, explaining the correlation between RAM and dataset size, and ways to tackle the issue. They both also discussed database-like query options.
Issue with Typesense Schema and Ruby Client
Mateo faces issues while creating a schema and using Ruby client for Typesense. Jason suggests using a new field instead of 'id' and provides assistance for Ruby client errors.
Changing Facet Value of Indexed Collections
Roshan wanted to alter the facet value of fields after indexing. Kishore Nallan explained the current limitation, suggested pre-creation of collection before syncing. Faceted search is also encountered an unknown issue, Kishore Nallan advised to raise the issue in Github.
Troubleshooting Search Function with Typesense
Rohan had trouble understanding how search functions in Typesense with email string fields. Kishore Nallan explained the logic of indexing and introduced new features in the 0.22 RC version, advised Rohan to create an issue regarding schema creation errors.
Optimizing JSON Data Import and Search with PHP Library
Arumugam experienced slow search results and data import time with json and PHP library. Kishore Nallan advised trying import and provided guidance on integrating the function into a PHP application. The issue was resolved as the search results are now displayed faster.