Skip to content

manticoresoftware/manticoresearch-java

Repository files navigation

Manticore Java client

❗ WARNING: this is a development version of the client. The latest release's readme is https://github.com/manticoresoftware/manticoresearch-java/tree/5.0.0

Manticore Search Client

  • API version: 6.0.0

  • Build date: 2024-10-28T14:26:41.232179329Z[Etc/UTC]

Сlient for Manticore Search.

Requirements

Building the API client library requires:

  1. Java 1.8+
  2. Maven/Gradle
Manticore Search manticoresearch-java
dev dev
>= 6.3.6 >= 5.0.x
>= 6.2.0 >= 3.3.1
>= 2.5.1 >= 2.0.2

Installation

To install the API client library to your local Maven repository, simply execute:

mvn clean install

To deploy it to a remote Maven repository instead, configure the settings of the repository and execute:

mvn clean deploy

Refer to the OSSRH Guide for more information.

Maven users

Add this dependency to your project's POM:

<dependency>
  <groupId>com.manticoresearch</groupId>
  <artifactId>manticoresearch</artifactId>
  <version>6.0.0</version>
  <scope>compile</scope>
</dependency>

Gradle users

Add this dependency to your project's build file:

  repositories {
    mavenCentral()     // Needed if the 'manticoresearch' jar has been published to maven central.
    mavenLocal()       // Needed if the 'manticoresearch' jar has been published to the local maven repo.
  }

  dependencies {
     implementation "com.manticoresearch:manticoresearch:6.0.0"
  }

Others

At first generate the JAR by executing:

mvn clean package

Then manually install the following JARs:

  • target/manticoresearch-6.0.0.jar
  • target/lib/*.jar

Getting Started

Please follow the installation instruction and execute the following Java code:

import com.manticoresearch.client.*;
import com.manticoresearch.client.auth.*;
import com.manticoresearch.client.model.*;
import com.manticoresearch.client.api.*;

public class ApiExample {

    public static void main(String[] args) {
        ApiClient defaultClient = Configuration.getDefaultApiClient();
        defaultClient.setBasePath("http://127.0.0.1:9308");
        
        IndexApi apiInstance = new IndexApi(defaultClient);
        String body = "body_example"; // String | 

		# Perform insert and search operations        
        SearchApi searchApi = new SearchApi(client);
        IndexApi indexApi = new IndexApi(client);
        try {
        	String tableName = "products";

			InsertDocumentRequest indexRequest = new InsertDocumentRequest();
        	HashMap<String,Object> doc = new HashMap<String,Object>();
        	indexRequest.index(tableName).id(1L).setDoc(doc); 
        	indexApi.insert(indexRequest);
        
            Highlight highlight = new Highlight();
			List<String> highlightFields = new ArrayList<String>();
	    	highlightFields.add("title");
			highlight.setFields(highlightFields);

			SearchQuery query = new SearchQuery();
			query.setQueryString("@title Bag");

			SearchRequest searchRequest = new SearchRequest();
			searchRequest.index(tableName).query(query).setHighlight(highlight);
					
			SearchResponse searchResponse = searchApi.search(searchRequest);
			System.out.println(searchResponse);
        } catch (ApiException e) {
            System.err.println("Exception when calling Api function");
            System.err.println("Status code: " + e.getCode());
            System.err.println("Reason: " + e.getResponseBody());
            System.err.println("Response headers: " + e.getResponseHeaders());
            e.printStackTrace();
        }
    }
}

Documentation for API Endpoints

All URIs are relative to http://127.0.0.1:9308

Class Method HTTP request Description
IndexApi bulk POST /bulk Bulk index operations
IndexApi delete POST /delete Delete a document in an index
IndexApi insert POST /insert Create a new document in an index
IndexApi partialReplace POST /{index}/_update/{id} Partially replaces a document in an index
IndexApi replace POST /replace Replace new document in an index
IndexApi update POST /update Update a document in an index
SearchApi percolate POST /pq/{index}/search Perform reverse search on a percolate index
SearchApi search POST /search Performs a search on an index
UtilsApi sql POST /sql Perform SQL requests

Documentation for Models

Documentation for Authorization

All endpoints do not require authorization. Authentication schemes defined for the API:

Recommendation

It's recommended to create an instance of ApiClient per thread in a multithreaded environment to avoid any potential issues.