Quick start guide
Install and start Manticore
You can install and start Manticore easily in Ubuntu, Centos, Debian, Windows and MacOS or use Manticore as a docker container.
- Ubuntu
- Debian
- Centos
- Windows
- MacOS
- Docker
Ubuntu Debian Centos Windows MacOS Docker
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
- Download Windows archive from https://manticoresearch.com/install/
- Extract all from the archive to C:\Manticore
C:\Manticore\bin\searchd --install --config C:\Manticore\sphinx.conf.in --servicename Manticore
Start Manticore from the Services snap-in of the Microsoft Management Console
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
Connect to Manticore
By default Manticore is waiting for your connections on:
- port 9306 for MySQL clients
- port 9308 for HTTP/HTTPS connections
- port 9312 for connections from other Manticore nodes and clients based on Manticore binary API
- SQL
- HTTP
- PHP
- Python
- Javascript
- Java
SQL HTTP PHP Python Javascript Java
mysql -h0 -P9306
HTTP is a stateless protocol so it doesn’t require any special connection phase:
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
config = manticoresearch.Configuration(
host = "http://127.0.0.1:9308"
)
client = manticoresearch.ApiClient(config)
indexApi = manticoresearch.IndexApi(client)
searchApi = manticoresearch.SearchApi(client)
utilsApi = manticoresearch.UtilsApi(client)
// https://github.com/manticoresoftware/manticoresearch-javascript
var Manticoresearch = require('manticoresearch');
var client= new Manticoresearch.ApiClient()
client.basePath="http://127.0.0.1:9308";
indexApi = new Manticoresearch.IndexApi(client);
searchApi = new Manticoresearch.SearchApi(client);
utilsApi = new Manticoresearch.UtilsApi(client);
// https://github.com/manticoresoftware/manticoresearch-java
import com.manticoresearch.client.*;
import com.manticoresearch.client.model.*;
import com.manticoresearch.client.api.*;
...
ApiClient client = Configuration.getDefaultApiClient();
client.setBasePath("http://127.0.0.1:9308");
...
IndexApi indexApi = new IndexApi(client);
SearchApi searchApi = new UtilsApi(client);
UtilsApi utilsApi = new UtilsApi(client);
Create a table
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.
- SQL
- HTTP
- PHP
- Python
- Javascript
- Java
SQL HTTP PHP Python Javascript Java
create table products(title text, price float) morphology='stem_en';
POST /cli -d "create table products(title text, price float) morphology='stem_en'"
$index = new \Manticoresearch\Index($client);
$index->setName('products');
$index->create([
'title'=>['type'=>'text'],
'price'=>['type'=>'float'],
],['morphology' => 'stem_en']);
utilsApi.sql('create table products(title text, price float) morphology=\'stem_en\'')
res = await utilsApi.sql('create table products(title text, price float) morphology=\'stem_en\'');
utilsApi.sql("create table products(title text, price float) morphology='stem_en'");
Response
Query OK, 0 rows affected (0.02 sec)
{
"total":0,
"error":"",
"warning":""
}
Add documents
Let’s now add few documents to the table:
- SQL
- JSON
- PHP
- Python
- Javascript
- Java
SQL JSON PHP Python Javascript Java
insert into products(title,price) values ('Crossbody Bag with Tassel', 19.85), ('microfiber sheet set', 19.99), ('Pet Hair Remover Glove', 7.99);
"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->addDocuments([
['title' => 'Crossbody Bag with Tassel', 'price' => 19.85],
['title' => 'microfiber sheet set', 'price' => 19.99],
['title' => 'Pet Hair Remover Glove', 'price' => 7.99]
]);
indexApi.insert({"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}})
res = 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}});
InsertDocumentRequest newdoc = new InsertDocumentRequest();
HashMap<String,Object> doc = new HashMap<String,Object>(){{
put("title","Crossbody Bag with Tassel");
put("price",19.85);
}};
newdoc.index("products").setDoc(doc);
sqlresult = indexApi.insert(newdoc);
newdoc = new InsertDocumentRequest();
doc = new HashMap<String,Object>(){{
put("title","microfiber sheet set");
put("price",19.99);
}};
newdoc.index("products").setDoc(doc);
sqlresult = indexApi.insert(newdoc);
newdoc = new InsertDocumentRequest();
doc = new HashMap<String,Object>(){{
put("title","Pet Hair Remover Glove");
put("price",7.99);
}};
newdoc.index("products").setDoc(doc);
indexApi.insert(newdoc);
Response
Query OK, 3 rows affected (0.01 sec)
{
"_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
}
Search
Let’s find one of the documents. The query we will use is ‘remove hair’. As you can see it finds document with 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"
).
- SQL
- JSON
- PHP
- Python
- javascript
- Java
SQL JSON PHP Python javascript Java
select id, highlight(), price from products where match('remove hair');
POST /search
{
"index": "products",
"query": { "match": { "title": "remove hair" } },
"highlight":
{
"fields": ["title"]
}
}
$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());
}
searchApi.search({"index":"myindex","query":{"query_string":"@title remove hair"},"highlight":{"fields":["title"]}})
res = await searchApi.search({"index":"myindex","query":{"query_string":"@title remove hair"}"highlight":{"fields":["title"]}});
query = new HashMap<String,Object>();
query.put("query_string","@title remove hair");
searchRequest = new SearchRequest();
searchRequest.setIndex("forum");
searchRequest.setQuery(query);
HashMap<String,Object> highlight = new HashMap<String,Object>(){{
put("fields",new String[] {"title"});
}};
searchRequest.setHighlight(highlight);
searchResponse = searchApi.search(searchRequest);
Response
+---------------------+-------------------------------+----------+
| id | highlight() | price |
+---------------------+-------------------------------+----------+
| 1513686608316989452 | Pet <strong>Hair Remover</strong> Glove | 7.990000 |
+---------------------+-------------------------------+----------+
1 row in set (0.00 sec)
{
"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 <strong>Hair Remover</strong> Glove"
]
}
}
]
}
}
Doc ID: 1513686608316989452
Doc Score: 1680
Document fields:
Array
(
[price] => 7.99
[title] => Pet Hair Remover Glove
)
Highlights:
Array
(
[title] => Array
(
[0] => Pet <strong>Hair Remover</strong> Glove
)
)
`
{'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 <strong>Hair Remover</strong> Glove']}}}],
'total': 1},
'profile': None,
'timed_out': False,
'took': 0}
{"hits": {"hits": [{"_id": "1513686608316989452",
"_score": 1680,
"_source": {"title": "Pet Hair Remover Glove", "price":7.99},
"highlight":{"title":["Pet <strong>Hair Remover</strong> Glove"]}}],
"total": 1},
"profile": None,
"timed_out": False,
"took": 0}
class SearchResponse {
took: 84
timedOut: false
hits: class SearchResponseHits {
total: 1
maxScore: null
hits: [{_id=1513686608316989452, _score=1, _source={price=7.99, title=Pet Hair Remover Glove}, highlight={title=[Pet <strong>Hair Remover</strong> Glove]}}]
aggregations: null
}
profile: null
}
Update
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.
- SQL
- JSON
- PHP
- Python
- javascript
- Java
SQL JSON PHP Python javascript Java
update products set price=18.5 where id = 1513686608316989452;
POST /update
{
"index": "products",
"id": 1513686608316989452,
"doc":
{
"price": 18.5
}
}
$doc = [
'body' => [
'index' => 'products',
'id' => 2,
'doc' => [
'price' => 18.5
]
]
];
$response = $client->update($doc);
indexApi = api = manticoresearch.IndexApi(client)
indexApi.update({"index" : "products", "id" : 1513686608316989452, "doc" : {"price":18.5}})
res = await indexApi.update({"index" : "products", "id" : 1513686608316989452, "doc" : {"price":18.5}});
UpdateDocumentRequest updateRequest = new UpdateDocumentRequest();
doc = new HashMap<String,Object >(){{
put("price",18.5);
}};
updateRequest.index("products").id(1513686608316989452L).setDoc(doc);
indexApi.update(updateRequest);
Response
Query OK, 1 row affected (0.00 sec)
{
"_index": "products",
"_id": 1513686608316989452,
"result": "updated"
}
Delete
Let’s now delete all documents with price lower than 10.
- SQL
- JSON
- PHP
- Python
- javascript
- Java
SQL JSON PHP Python javascript Java
delete from products where price < 10;
POST /delete
{
"index": "products",
"query":
{
"range":
{
"price":
{
"lte": 10
}
}
}
}
$result = $index->deleteDocuments(new \Manticoresearch\Query\Range('price',['lte'=>10]));
indexApi.delete({"index" : "products", "query": {"range":{"price":{"lte":10}}}})
res = await indexApi.delete({"index" : "products", "query": {"range":{"price":{"lte":10}}}});
DeleteDocumentRequest deleteRequest = new DeleteDocumentRequest();
query = new HashMap<String,Object>();
query.put("range",new HashMap<String,Object>(){{
put("range",new HashMap<String,Object>(){{
put("lte",10);
}});
}});
deleteRequest.index("products").setQuery(query);
indexApi.delete(deleteRequest);
Response
Query OK, 1 row affected (0.00 sec)
{
"_index": "products",
"deleted": 1
}
Array
(
[_index] => products
[deleted] => 1
)
Starting the server
Manticore Search server can be started in several ways, depending on how it was installed.
Starting Manticore in Linux
When Manticore Search is installed using DEB or RPM packages, the searchd process can be run and managed by operating system’s init system. Most Linux versions now use systemd, while older releases use SysV init.
If you are not sure about the type of the init system your platform use, run:
ps --no-headers -o comm 1
Starting and stopping using systemd
After the installation the Manticore Search service is not started automatically. To start Manticore run the following command:
sudo systemctl start manticore
To stop Manticore run the following command:
sudo systemctl stop manticore
The Manticore service is set to run at boot. You can check it by running:
sudo systemctl is-enabled manticore
If you want to disable Manticore starting at boot time run:
sudo systemctl disable manticore
To make Manticore start at boot, run:
sudo systemctl enable manticore
In some newer operating systems it can fail with error “Failed to enable unit: Unit … is transient or generated.”. In this case you can remove the generator and try again. It’s unlikely you need the generator ever again after Manticore is installed.
In Debian-based operating systems run:
sudo rm /lib/systemd/system-generators/manticore-generator
sudo systemctl daemon-reload
In CentOS and RHEL run:
sudo rm /usr/lib/systemd/system-generators/manticore-search-generator
sudo systemctl daemon-reload
If you still need the generator again just install the Manticore packages again and it will recover the generator file.
searchd
process logs startup information in systemd
journal. If systemd
logging is enabled you can view the logged information with the following command:
sudo journalctl --unit manticore
Custom startup flags using systemd
systemctl set-environment _ADDITIONAL_SEARCHD_PARAMS
allows you to specify custom startup flags Manticore Search daemon should be started with. See full list here.
For example, to start Manticore with debug logging level you can run:
systemctl set-environment _ADDITIONAL_SEARCHD_PARAMS='--logdebug'
systemctl restart manticore
To undo it run:
systemctl set-environment _ADDITIONAL_SEARCHD_PARAMS=''
systemctl restart manticore
Note, systemd environment variables get reset on server reboot.
Starting and stopping using service
Manticore can be started and stopped using service commands:
sudo service manticore start
sudo service manticore stop
To enable the sysV service at boot on RedHat systems run:
chkconfig manticore on
To enable the sysV service at boot on Debian systems (including Ubuntu) run:
update-rc.d manticore defaults
Please note that searchd
is started by the init system under manticore
user and all files created by the server will be owned by this user. If searchd
is started under ,for example, root user, the permissions of files will be changed which may lead to issues when running again searchd
as service.