You are currently browsing legacy 3.0 version of documentation. Click here to switch to the newest 5.0 version.

We can help you with migration to the latest RavenDB

Contact Us Now
see on GitHub

Commands: Indexes: Put

PutIndex

PutIndex is used to insert an index into a database.

Syntax

curl \
	http://{serverName}/databases/{databaseName}/indexes/{indexName}?definition=yes \
	-X PUT \
	-d @indexDefinition.txt
Payload
Index Definition
Query parameter Required Description
indexName Yes Name of an index

Response

Status code Description
201 Created
Return Value Description
Index Index name

Example

curl -X PUT "http://localhost:8080/databases/NorthWind/indexes/Orders/Totals?definition=yes" \
 -d " {\"MaxIndexOutputsPerDocument\":null, \
	\"IndexId\":0, \
	\"Name\":null, \
	\"LockMode\":\"Unlock\", \
	\"Maps\":[\" from order in docs.Orders  select new  {     order.Employee,    order.Company,    Total = order.Lines.Sum(l => (l.Quantity * l.PricePerUnit) * (1 - l.Discount))}\"], \
	\"Reduce\":null, \
	\"Stores\":{}, \
	\"Indexes\":{}, \
	\"SortOptions\":{}, \
	\"Analyzers\":{}, \
	\"Fields\":[], \
	\"Suggestions\":{}, \
	\"TermVectors\":{}, \
	\"SpatialIndexes\":{}, \
	\"DisableInMemoryIndexing\":false, \
	\"Type\":\"Map\", \
	\"Map\":\" from order in docs.Orders  select new  {     order.Employee,    order.Company,    Total = order.Lines.Sum(l => (l.Quantity * l.PricePerUnit) * (1 - l.Discount))}\", \
	\"IsCompiled\":false, \
	\"IsMapReduce\":false} "
< HTTP/1.1 201 Created
{"Index":"Orders/Totals"}

PutIndexes

PutIndexes creates multiple indexes with specified names, using given index definitions and priorities.

Syntax

curl \
	http://{serverName}/databases/{databaseName}/indexes \
	-X PUT \
	-d @indexesToAdd.txt
Payload
Array of IndexToAdd objects

Response

Status code Description
201 Created
Return Value Description
Indexes[] Array of names of created indexes

Example

curl -X PUT "http://localhost:8080/databases/NorthWind/indexes" \
 -d "[{'Name':'Orders/Totals', \
    'Definition':{ \
    'MaxIndexOutputsPerDocument':null, \
    'IndexId':0, \
    'Name':null, \
    'LockMode':'Unlock', \
    'Maps':['from order in docs.Orders  select new  {     order.Employee,    order.Company,    Total = order.Lines.Sum(l => (l.Quantity * l.PricePerUnit) * (1 - l.Discount))}'], \
    'Reduce':null, \
    'Stores':{}, \
    'Indexes':{}, \
    'SortOptions':{}, \
    'Analyzers':{}, \
    'Fields':[], \
    'Suggestions':{}, \
    'TermVectors':{}, \
    'SpatialIndexes':{}, \
    'DisableInMemoryIndexing':false, \
    'Type':'Map', \
    'Map':' from order in docs.Orders  select new  {     order.Employee,    order.Company,    Total = order.Lines.Sum(l => (l.Quantity * l.PricePerUnit) * (1 - l.Discount))}', \
    'IsCompiled':false, \
    'IsMapReduce':false \
    }, \
'Priority':'Normal'}, \
{'Name':'Product/Sales', \
    'Definition':{ \
    'MaxIndexOutputsPerDocument':null, \
    'IndexId':0, \
    'Name':null, \
    'LockMode':'Unlock', \
    'Maps':['from order in docs.Orders from line in order.Lines select new { Product = line.Product, Count = 1, Total = ((line.Quantity * line.PricePerUnit) *  ( 1 - line.Discount)) }'], \
    'Reduce':null, \
    'Stores':{}, \
    'Indexes':{}, \
    'SortOptions':{}, \
    'Analyzers':{}, \
    'Fields':[], \
    'Suggestions':{}, \
    'TermVectors':{}, \
    'SpatialIndexes':{}, \
    'DisableInMemoryIndexing':false, \
    'Type':'MapReduce', \
    'Map':'from order in docs.Orders from line in order.Lines select new { Product = line.Product, Count = 1, Total = ((line.Quantity * line.PricePerUnit) *  ( 1 - line.Discount)) }', \
    'IsCompiled':false, \
    'IsMapReduce':false \
    }, \
'Priority':'Normal'}]"
< HTTP/1.1 201 Created
{"Indexes":["Orders/Totals", "Product/Sales"]}