Created
March 27, 2013 15:59
-
-
Save emedina/5255378 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Remove all data. | |
curl -XDELETE 'http://127.0.0.1:9200/poc/' | |
# Create index with default settings. | |
curl -XPUT 'http://127.0.0.1:9200/poc/' | |
# Define mapping for taskA. | |
curl -XPUT 'http://127.0.0.1:9200/poc/taskA/_mapping' -d ' | |
{ | |
"taskA": { | |
"properties": { | |
"taskId": { "type": "string" }, | |
"milestone": { "type": "integer" } | |
} | |
} | |
} | |
' | |
# Define mapping for taskB. | |
curl -XPUT 'http://127.0.0.1:9200/poc/taskB/_mapping' -d ' | |
{ | |
"taskB": { | |
"properties": { | |
"taskId": { "type": "string" }, | |
"legalstatus": { "type": "integer" } | |
} | |
} | |
} | |
' | |
# Insert some data. | |
curl -XPOST 'http://127.0.0.1:9200/poc/taskA/' -d ' | |
{ | |
"taskId": "001927368", | |
"milestone": 5 | |
} | |
' | |
curl -XPOST 'http://127.0.0.1:9200/poc/taskA/' -d ' | |
{ | |
"taskId": "002837463", | |
"milestone": 2 | |
} | |
' | |
curl -XPOST 'http://127.0.0.1:9200/poc/taskA/' -d ' | |
{ | |
"taskId": "872356274", | |
"milestone": 1 | |
} | |
' | |
curl -XPOST 'http://127.0.0.1:9200/poc/taskA/' -d ' | |
{ | |
"taskId": "192837465", | |
"milestone": 5 | |
} | |
' | |
curl -XPOST 'http://127.0.0.1:9200/poc/taskA/' -d ' | |
{ | |
"taskId": "172283644", | |
"milestone": 5 | |
} | |
' | |
curl -XPOST 'http://127.0.0.1:9200/poc/taskB/' -d ' | |
{ | |
"taskId": "873482322", | |
"legalstatus": 10 | |
} | |
' | |
curl -XPOST 'http://127.0.0.1:9200/poc/taskB/' -d ' | |
{ | |
"taskId": "000093556", | |
"legalstatus": 15 | |
} | |
' | |
curl -XPOST 'http://127.0.0.1:9200/poc/taskB/' -d ' | |
{ | |
"taskId": "000222267", | |
"legalstatus": 12 | |
} | |
' | |
# Search with combined criteria from both types. | |
# For instance, "give me all the taskA with milestone = 5, and the taskB with legalstatus = 12" | |
curl -XPOST 'http://127.0.0.1:9200/poc/_search?pretty=true' -d ' | |
{ | |
"query": { | |
"filtered": { | |
"query": { | |
"match_all": {} | |
}, | |
"filter": { | |
"or": [ | |
{ | |
"and": [ | |
{ | |
"term": { | |
"milestone": 5 | |
} | |
}, | |
{ | |
"type": { | |
"value": "taskA" | |
} | |
} | |
] | |
}, | |
{ | |
"and": [ | |
{ | |
"term": { | |
"legalstatus": 12 | |
} | |
}, | |
{ | |
"type": { | |
"value": "taskB" | |
} | |
} | |
] | |
} | |
] | |
} | |
} | |
} | |
} | |
' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment