You can install and start Manticore easily on various operating systems, including Ubuntu, Centos, Debian, Windows, and MacOS. Additionally, you can also use Manticore as a Docker container.
wget https://repo.manticoresearch.com/manticore-repo.noarch.deb
sudo dpkg -i manticore-repo.noarch.deb
sudo apt update
sudo apt install manticore manticore-columnar-lib
sudo systemctl start manticore
wget https://repo.manticoresearch.com/manticore-repo.noarch.deb
sudo dpkg -i manticore-repo.noarch.deb
sudo apt update
sudo apt install manticore manticore-columnar-lib
sudo systemctl start manticore
sudo yum install https://repo.manticoresearch.com/manticore-repo.noarch.rpm
sudo yum install manticore manticore-columnar-lib
sudo systemctl start manticore
C:\Manticore
C:\Manticore\bin\searchd --install --config C:\Manticore\sphinx.conf.in --servicename Manticore
brew install manticoresearch
brew services start manticoresearch
docker pull manticoresearch/manticore
docker run -e EXTRA=1 --name manticore -p9306:9306 -p9308:9308 -p9312:9312 -d manticoresearch/manticore
For persisting your data directory, read how to use Manticore docker in production
By default Manticore is waiting for your connections on:
mysql -h0 -P9306
HTTP is a stateless protocol, so it doesn’t require any special connection phase. You can simply send a HTTP request to the server and receive the response. To communicate with Manticore using the HTTP interface, you can use any HTTP client library in your programming language of choice to send GET or POST requests to the server and parse the JSON responses:
curl -s "http://localhost:9308/search"
// https://github.com/manticoresoftware/manticoresearch-php
require_once __DIR__ . '/vendor/autoload.php';
$config = ['host'=>'127.0.0.1','port'=>9308];
$client = new \Manticoresearch\Client($config);
// https://github.com/manticoresoftware/manticoresearch-python
import manticoresearch
= manticoresearch.Configuration(
config = "http://127.0.0.1:9308"
host
)= manticoresearch.ApiClient(config)
client = manticoresearch.IndexApi(client)
indexApi = manticoresearch.SearchApi(client)
searchApi = manticoresearch.UtilsApi(client) utilsApi
// https://github.com/manticoresoftware/manticoresearch-javascript
var Manticoresearch = require('manticoresearch');
var client= new Manticoresearch.ApiClient()
.basePath="http://127.0.0.1:9308";
client= new Manticoresearch.IndexApi(client);
indexApi = new Manticoresearch.SearchApi(client);
searchApi = new Manticoresearch.UtilsApi(client); utilsApi
// https://github.com/manticoresoftware/manticoresearch-java
import com.manticoresearch.client.*;
import com.manticoresearch.client.model.*;
import com.manticoresearch.client.api.*;
...Configuration.getDefaultApiClient();
ApiClient client = setBasePath("http://127.0.0.1:9308");
client.
...new IndexApi(client);
IndexApi indexApi = new UtilsApi(client);
SearchApi searchApi = new UtilsApi(client); UtilsApi utilsApi =
Let’s now create a table called “products” with 2 fields: * title - full-text field which will contain our product’s title * price - of type “float”
Note that it is possible to omit creating a table with an explicit create statement. For more information, see Auto schema.
create table products(title text, price float) morphology='stem_en';
Query OK, 0 rows affected (0.02 sec)
POST /cli -d "create table products(title text, price float) morphology='stem_en'"
{
"total":0,
"error":"",
"warning":""
}
$index = new \Manticoresearch\Index($client);
$index->setName('products');
$index->create([
'title'=>['type'=>'text'],
'price'=>['type'=>'float'],
],['morphology' => 'stem_en']);
'create table products(title text, price float) morphology=\'stem_en\'') utilsApi.sql(
= await utilsApi.sql('create table products(title text, price float) morphology=\'stem_en\''); res
sql("create table products(title text, price float) morphology='stem_en'"); utilsApi.
Let’s now add few documents to the table:
insert into products(title,price) values ('Crossbody Bag with Tassel', 19.85), ('microfiber sheet set', 19.99), ('Pet Hair Remover Glove', 7.99);
Query OK, 3 rows affected (0.01 sec)
"id":0
or no id forces automatic ID generation.
POST /insert
{
"index":"products",
"doc":
{
"title" : "Crossbody Bag with Tassel",
"price" : 19.85
}
}
POST /insert
{
"index":"products",
"doc":
{
"title" : "microfiber sheet set",
"price" : 19.99
}
}
POST /insert
{
"index":"products",
"doc":
{
"title" : "Pet Hair Remover Glove",
"price" : 7.99
}
}
{
"_index": "products",
"_id": 0,
"created": true,
"result": "created",
"status": 201
}
{
"_index": "products",
"_id": 0,
"created": true,
"result": "created",
"status": 201
}
{
"_index": "products",
"_id": 0,
"created": true,
"result": "created",
"status": 201
}
$index->addDocuments([
['title' => 'Crossbody Bag with Tassel', 'price' => 19.85],
['title' => 'microfiber sheet set', 'price' => 19.99],
['title' => 'Pet Hair Remover Glove', 'price' => 7.99]
]);
"index" : "test", "doc" : {"title" : "Crossbody Bag with Tassel", "price" : 19.85}})
indexApi.insert({"index" : "test", "doc" : {"title" : "microfiber sheet set", "price" : 19.99}})
indexApi.insert({"index" : "test", "doc" : {"title" : "Pet Hair Remover Glove", "price" : 7.99}}) indexApi.insert({
= await indexApi.insert({"index" : "test", "doc" : {"title" : "Crossbody Bag with Tassel", "price" : 19.85}});
res = await indexApi.insert({"index" : "test", "doc" : {"title" : "microfiber sheet set", "price" : 19.99}});
res = await indexApi.insert({"index" : "test", doc" : {"title" : "Pet Hair Remover Glove", "price" : 7.99}}); res
new InsertDocumentRequest();
InsertDocumentRequest newdoc = HashMap<String,Object> doc = new HashMap<String,Object>(){{
put("title","Crossbody Bag with Tassel");
put("price",19.85);
}};index("products").setDoc(doc);
newdoc.insert(newdoc);
sqlresult = indexApi.
new InsertDocumentRequest();
newdoc = new HashMap<String,Object>(){{
doc = put("title","microfiber sheet set");
put("price",19.99);
}};index("products").setDoc(doc);
newdoc.insert(newdoc);
sqlresult = indexApi.
new InsertDocumentRequest();
newdoc = new HashMap<String,Object>(){{
doc = put("title","Pet Hair Remover Glove");
put("price",7.99);
}};index("products").setDoc(doc);
newdoc.insert(newdoc); indexApi.
Let’s find one of the documents. The query we will use is ‘remove hair’. As you can see, it finds a document with the title ‘Pet Hair Remover Glove’ and highlights ‘Hair remover’ in it, even though the query has “remove”, not “remover”. This is because when we created the table, we turned on using English stemming (morphology "stem_en"
).
select id, highlight(), price from products where match('remove hair');
+---------------------+-------------------------------+----------+
id | highlight() | price |
| +---------------------+-------------------------------+----------+
1513686608316989452 | Pet <b>Hair Remover</b> Glove | 7.990000 |
| +---------------------+-------------------------------+----------+
1 row in set (0.00 sec)
POST /search
{
"index": "products",
"query": { "match": { "title": "remove hair" } },
"highlight":
{
"fields": ["title"]
}
}
{
"took": 0,
"timed_out": false,
"hits": {
"total": 1,
"hits": [
{
"_id": "1513686608316989452",
"_score": 1680,
"_source": {
"price": 7.99,
"title": "Pet Hair Remover Glove"
},
"highlight": {
"title": [
"Pet <b>Hair Remover</b> Glove"
]
}
}
]
}
}
$result = $index->search('@title remove hair')->highlight(['title'])->get();
foreach($result as $doc)
{echo "Doc ID: ".$doc->getId()."\n";
echo "Doc Score: ".$doc->getScore()."\n";
echo "Document fields:\n";
print_r($doc->getData());
echo "Highlights: \n";
print_r($doc->getHighlight());
}
ID: 1513686608316989452
Doc 1680
Doc Score:
Document fields:Array
(
[price] => 7.99
[title] => Pet Hair Remover Glove
)
Highlights:Array
(
[title] => Array
(
[0] => Pet <b>Hair Remover</b> Glove
)
)
`
Python
"index":"myindex","query":{"query_string":"@title remove hair"},"highlight":{"fields":["title"]}}) searchApi.search({
'hits': {'hits': [{u'_id': u'1513686608316989452',
{u'_score': 1680,
u'_source': {u'title': u'Pet Hair Remover Glove', u'price':7.99},
u'highlight':{u'title':[u'Pet <b>Hair Remover</b> Glove']}}}],
'total': 1},
'profile': None,
'timed_out': False,
'took': 0}
javascript
= await searchApi.search({"index":"myindex","query":{"query_string":"@title remove hair"}"highlight":{"fields":["title"]}}); res
"hits": {"hits": [{"_id": "1513686608316989452",
{"_score": 1680,
"_source": {"title": "Pet Hair Remover Glove", "price":7.99},
"highlight":{"title":["Pet <b>Hair Remover</b> Glove"]}}],
"total": 1},
"profile": None,
"timed_out": False,
"took": 0}
java
new HashMap<String,Object>();
query = put("query_string","@title remove hair");
query.new SearchRequest();
searchRequest = setIndex("forum");
searchRequest.setQuery(query);
searchRequest.HashMap<String,Object> highlight = new HashMap<String,Object>(){{
put("fields",new String[] {"title"});
}};setHighlight(highlight);
searchRequest.search(searchRequest); searchResponse = searchApi.
class SearchResponse {
84
took: false
timedOut: class SearchResponseHits {
hits: 1
total: null
maxScore: 1513686608316989452, _score=1, _source={price=7.99, title=Pet Hair Remover Glove}, highlight={title=[Pet <b>Hair Remover</b> Glove]}}]
hits: [{_id=null
aggregations:
}null
profile:
}
Let’s assume we now want to update the document - change the price to 18.5. This can be done by filtering by any field, but normally you know the document id and update something based on that.
update products set price=18.5 where id = 1513686608316989452;
Query OK, 1 row affected (0.00 sec)
POST /update
{
"index": "products",
"id": 1513686608316989452,
"doc":
{
"price": 18.5
}
}
{
"_index": "products",
"_id": 1513686608316989452,
"result": "updated"
}
$doc = [
'body' => [
'index' => 'products',
'id' => 2,
'doc' => [
'price' => 18.5
]
]
];
$response = $client->update($doc);
= api = manticoresearch.IndexApi(client)
indexApi "index" : "products", "id" : 1513686608316989452, "doc" : {"price":18.5}}) indexApi.update({
= await indexApi.update({"index" : "products", "id" : 1513686608316989452, "doc" : {"price":18.5}}); res
new UpdateDocumentRequest();
UpdateDocumentRequest updateRequest = new HashMap<String,Object >(){{
doc = put("price",18.5);
}};index("products").id(1513686608316989452L).setDoc(doc);
updateRequest.update(updateRequest); indexApi.
Let’s now delete all documents with price lower than 10.
delete from products where price < 10;
Query OK, 1 row affected (0.00 sec)
POST /delete
{
"index": "products",
"query":
{
"range":
{
"price":
{
"lte": 10
}
}
}
}
{
"_index": "products",
"deleted": 1
}
$result = $index->deleteDocuments(new \Manticoresearch\Query\Range('price',['lte'=>10]));
Array
(
[_index] => products
[deleted] => 1
)
"index" : "products", "query": {"range":{"price":{"lte":10}}}}) indexApi.delete({
= await indexApi.delete({"index" : "products", "query": {"range":{"price":{"lte":10}}}}); res
new DeleteDocumentRequest();
DeleteDocumentRequest deleteRequest = new HashMap<String,Object>();
query = put("range",new HashMap<String,Object>(){{
query.put("range",new HashMap<String,Object>(){{
put("lte",10);
}});
}});index("products").setQuery(query);
deleteRequest.delete(deleteRequest); indexApi.