Created
January 26, 2015 08:43
-
-
Save naro/3ad9a1c85f03c631e02a 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
curl -XDELETE "http://localhost:9200/test" | |
curl -XPOST "http://localhost:9200/test" -d' | |
{ | |
"mappings": { | |
"profile": { | |
"properties": { | |
"department": {"type": "string", "index": "not_analyzed"}, | |
"title": {"type": "string"}, | |
"email": {"type": "string", "index": "not_analyzed"}, | |
"num_all": {"type": "integer"}, | |
"publications": { | |
"type": "object", | |
"properties": { | |
"title": {"type": "string"}, | |
"categories": {"type": "string"} | |
} | |
} | |
} | |
}, | |
"publication": { | |
"properties": { | |
"department": {"type": "string", "index": "not_analyzed"}, | |
"title": {"type": "string"}, | |
"description": {"type": "string"}, | |
"text": {"type": "string"}, | |
"publication_type": {"type": "string", "index": "not_analyzed"}, | |
"categories": {"type": "string"}, | |
"num_all": {"type": "integer"}, | |
"profiles": { | |
"type": "object", | |
"properties": { | |
"title": {"type": "string"}, | |
"email": {"type": "string"}, | |
"department": {"type": "string"} | |
} | |
} | |
} | |
} | |
} | |
}' | |
curl -XPOST "http://localhost:9200/test/profile/1" -d' | |
{ | |
"department": "DEP 1", | |
"title": "John Doe", | |
"email": "john@doe.com", | |
"num_all": 2, | |
"publications": [ | |
{ | |
"title": "Publication 1", | |
"categories": ["cat 1", "cat 2", "cat 4"] | |
}, | |
{ | |
"title": "Publication 2", | |
"categories": ["cat 1"] | |
} | |
] | |
}' | |
curl -XPOST "http://localhost:9200/test/profile/2" -d' | |
{ | |
"department": "DEP 1", | |
"title": "Peter Doe", | |
"email": "peter@doe.com", | |
"num_all": 1, | |
"publications": [ | |
{ | |
"title": "Publication 2", | |
"categories": ["cat 1"] | |
} | |
] | |
}' | |
curl -XPOST "http://localhost:9200/test/profile/3 " -d' | |
{ | |
"department": "DEP 2", | |
"title": "Maria Doe", | |
"email": "Maria@doe.com", | |
"num_all": 2, | |
"publications": [ | |
{ | |
"title": "Publication 2", | |
"categories": ["cat 1"] | |
}, | |
{ | |
"title": "Publication 3", | |
"categories": ["cat 3"] | |
} | |
] | |
}' | |
curl -XPOST "http://localhost:9200/test/publication/1" -d' | |
{ | |
"department": "DEP 1", | |
"title": "Publication 1", | |
"categories": ["cat 1", "cat 2", "cat 4"], | |
"publication_type": "Journal", | |
"num_all": 1, | |
"profiles": [ | |
{ | |
"title": "John Doe", | |
"email": "john@doe.com" | |
} | |
] | |
}' | |
curl -XPOST "http://localhost:9200/test/publication/2" -d' | |
{ | |
"department": "DEP 2", | |
"title": "Publication 2", | |
"categories": ["cat 1"], | |
"publication_type": "Book", | |
"num_all": 2, | |
"profiles": [ | |
{ | |
"title": "Peter Doe", | |
"email": "peter@doe.com" | |
}, | |
{ | |
"title": "Maria Doe", | |
"email": "maria@doe.com" | |
} | |
] | |
}' | |
curl -XPOST "http://localhost:9200/test/publication/3" -d' | |
{ | |
"department": "DEP 2", | |
"title": "Publication 3", | |
"categories": ["cat 3"], | |
"publication_type": "Journal", | |
"num_all": 1, | |
"profiles": [ | |
{ | |
"title": "Maria Doe", | |
"email": "maria@doe.com" | |
} | |
] | |
}' | |
curl -XPOST "http://localhost:9200/test/_search?format=yaml" -d' | |
{ | |
"size": 0, | |
"query": { | |
"filtered": { | |
"query": { | |
"function_score": { | |
"query": { | |
"multi_match": { | |
"query": "doe", | |
"operator": "and", | |
"type": "cross_fields", | |
"fields": ["title^4", "categories^4", "*.categories^2", "*.title^2", "description", "text"] | |
} | |
}, | |
"functions": [ | |
{ | |
"field_value_factor": { | |
"field": "num_all", | |
"factor": 1.0, | |
"modifier": "log1p" | |
}, | |
"weight": 1.0 | |
} | |
] | |
} | |
} | |
} | |
}, | |
"aggs": { | |
"by_type": { | |
"terms": { | |
"field": "_type", | |
"size": 0 | |
}, | |
"aggs": { | |
"tops": { | |
"top_hits": { | |
"from": 0, | |
"size": 10 | |
} | |
} | |
} | |
}, | |
"by_department": { | |
"terms": { | |
"field": "department" | |
} | |
}, | |
"by_publication_type": { | |
"terms": { | |
"field": "publication_type" | |
} | |
} | |
} | |
}' | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment