Create Index
curl -XPUT 'localhost:9200/auto?pretty' -H 'Content-Type: application/json' -d'
{
"settings" : {
"number_of_shards" : 1
},
"mappings" : {
"car" : {
"properties" : {
"vol" : { "type" : "text" },
"fuel" : { "type" : "text" },
"transmission" : { "type" : "text" }
}
}
}
}
'
Add Data
curl -XPOST 'localhost:9200/auto/car' -H 'Content-Type: application/json' -d'
{
"vol" : "1.2",
"fuel" : "diesel",
"transmission" : "manual"
}
'
curl -XPOST 'localhost:9200/auto/car' -H 'Content-Type: application/json' -d'
{
"vol" : "1.6",
"fuel" : "diesel",
"transmission" : "automatic"
}
'
curl -XPOST 'localhost:9200/auto/car' -H 'Content-Type: application/json' -d'
{
"vol" : "2.0",
"fuel" : "diesel",
"transmission" : "automatic"
}
'
Make Query
curl -XGET 'localhost:9200/auto/_search?pretty' -H 'Content-Type: application/json' -d'
{
"query": {
"multi_match": {
"query": "2.0 diesel automatic",
"type": "cross_fields",
"operator": "or",
"fields": [ "vol", "fuel", "transmission" ]
}
}
}
'
'
RESULT:
{
"took" : 2,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"failed" : 0
},
"hits" : {
"total" : 3,
"max_score" : 1.5843642,
"hits" : [
{
"_index" : "auto",
"_type" : "car",
"_id" : "AV3wUm_rsk3AIfLZfnOJ",
"_score" : 1.5843642,
"_source" : {
"vol" : "2.0",
"fuel" : "diesel",
"transmission" : "automatic"
}
},
{
"_index" : "auto",
"_type" : "car",
"_id" : "AV3wUl7Fsk3AIfLZfnOI",
"_score" : 0.60353506,
"_source" : {
"vol" : "1.6",
"fuel" : "diesel",
"transmission" : "automatic"
}
},
{
"_index" : "auto",
"_type" : "car",
"_id" : "AV3wUlAFsk3AIfLZfnOH",
"_score" : 0.13353139,
"_source" : {
"vol" : "1.2",
"fuel" : "diesel",
"transmission" : "manual"
}
}
]
}
}