Created
February 11, 2014 17:52
-
-
Save alexbrasetvik/8940202 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
kol_tags: | |
scored: | |
- name: "Core Grower" | |
score: 36 | |
- name: "Connectivity" | |
score: 42 | |
--- | |
kol_tags: | |
scored: | |
- name: "Connectivity" | |
score: 34 | |
- name: "Connectivity" | |
score: 42 | |
--- | |
kol_tags: | |
scored: | |
- name: "Core Grower" | |
score: 36 | |
--- | |
kol_tags: | |
scored: | |
- name: "Connectivity" | |
score: 36 |
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
type: | |
properties: | |
kol_tags: | |
properties: | |
scored: | |
type: nested | |
properties: | |
name: | |
type: string | |
index: not_analyzed | |
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
#!/bin/bash | |
export ELASTICSEARCH_ENDPOINT="http://localhost:9200" | |
# Create indexes | |
curl -XPUT "$ELASTICSEARCH_ENDPOINT/play" -d '{ | |
"mappings": { | |
"type": { | |
"properties": { | |
"kol_tags": { | |
"properties": { | |
"scored": { | |
"type": "nested", | |
"properties": { | |
"name": { | |
"type": "string", | |
"index": "not_analyzed" | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
}' | |
# Index documents | |
curl -XPOST "$ELASTICSEARCH_ENDPOINT/_bulk?refresh=true" -d ' | |
{"index":{"_index":"play","_type":"type"}} | |
{"kol_tags":{"scored":[{"name":"Core Grower","score":36},{"name":"Connectivity","score":42}]}} | |
{"index":{"_index":"play","_type":"type"}} | |
{"kol_tags":{"scored":[{"name":"Connectivity","score":34},{"name":"Connectivity","score":42}]}} | |
{"index":{"_index":"play","_type":"type"}} | |
{"kol_tags":{"scored":[{"name":"Core Grower","score":36}]}} | |
{"index":{"_index":"play","_type":"type"}} | |
{"kol_tags":{"scored":[{"name":"Connectivity","score":36}]}} | |
' | |
# Do searches | |
curl -XPOST "$ELASTICSEARCH_ENDPOINT/_search?pretty" -d ' | |
{ | |
"query": { | |
"filtered": { | |
"filter": { | |
"bool": { | |
"should": [ | |
{ | |
"nested": { | |
"path": "kol_tags.scored", | |
"filter": { | |
"bool": { | |
"must": [ | |
{ | |
"term": { | |
"name": "Core Grower" | |
} | |
}, | |
{ | |
"range": { | |
"score": { | |
"gte": 1, | |
"lte": 100 | |
} | |
} | |
} | |
] | |
} | |
} | |
} | |
}, | |
{ | |
"nested": { | |
"path": "kol_tags.scored", | |
"filter": { | |
"bool": { | |
"must": [ | |
{ | |
"term": { | |
"name": "Connectivity" | |
} | |
}, | |
{ | |
"range": { | |
"score": { | |
"gte": 35, | |
"lte": 65 | |
} | |
} | |
} | |
] | |
} | |
} | |
} | |
} | |
], | |
"must_not": [ | |
{ | |
"nested": { | |
"path": "kol_tags.scored", | |
"filter": { | |
"bool": { | |
"must": [ | |
{ | |
"term": { | |
"name": "Connectivity" | |
} | |
}, | |
{ | |
"not": { | |
"range": { | |
"score": { | |
"gte": 35, | |
"lte": 65 | |
} | |
} | |
} | |
} | |
] | |
} | |
} | |
} | |
} | |
] | |
} | |
} | |
} | |
} | |
} | |
' | |
curl -XPOST "$ELASTICSEARCH_ENDPOINT/_search?pretty" -d ' | |
{ | |
"filter": { | |
"nested": { | |
"path": "kol_tags.scored", | |
"filter": { | |
"or": [ | |
{ | |
"and": [ | |
{ | |
"terms": { | |
"kol_tags.scored.name": [ | |
"Core Grower" | |
] | |
} | |
}, | |
{ | |
"range": { | |
"kol_tags.scored.score": { | |
"gte": 1, | |
"lte": 100 | |
} | |
} | |
} | |
] | |
}, | |
{ | |
"and": [ | |
{ | |
"terms": { | |
"kol_tags.scored.name": [ | |
"Connectivity" | |
] | |
} | |
}, | |
{ | |
"range": { | |
"kol_tags.scored.score": { | |
"gte": 35, | |
"lte": 65 | |
} | |
} | |
} | |
] | |
} | |
] | |
} | |
} | |
} | |
} | |
' | |
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
# Auto generated by Found's Play-tool at 2014-02-11T18:52:13+01:00 | |
version: 0 | |
title: Bools on nested filters | |
description: "" |
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
# In reply to http://stackoverflow.com/questions/21691882/nested-filter-query-with-exclusionary-ors | |
# Original search below | |
query: | |
filtered: | |
filter: | |
bool: | |
should: | |
- nested: | |
path: kol_tags.scored | |
filter: | |
bool: | |
must: | |
- term: | |
name: "Core Grower" | |
- range: | |
score: | |
gte: 1 | |
lte: 100 | |
- nested: | |
path: kol_tags.scored | |
filter: | |
bool: | |
must: | |
- term: | |
name: "Connectivity" | |
- range: | |
score: | |
gte: 35 | |
lte: 65 | |
must_not: | |
- nested: | |
path: kol_tags.scored | |
filter: | |
bool: | |
must: | |
- term: | |
name: "Connectivity" | |
- not: | |
range: | |
score: | |
gte: 35 | |
lte: 65 | |
--- | |
{ | |
"filter": { | |
"nested": { | |
"path": "kol_tags.scored", | |
"filter": { | |
"or": [ | |
{ | |
"and": [ | |
{ | |
"terms": { | |
"kol_tags.scored.name": [ | |
"Core Grower" | |
] | |
} | |
}, | |
{ | |
"range": { | |
"kol_tags.scored.score": { | |
"gte": 1, | |
"lte": 100 | |
} | |
} | |
} | |
] | |
}, | |
{ | |
"and": [ | |
{ | |
"terms": { | |
"kol_tags.scored.name": [ | |
"Connectivity" | |
] | |
} | |
}, | |
{ | |
"range": { | |
"kol_tags.scored.score": { | |
"gte": 35, | |
"lte": 65 | |
} | |
} | |
} | |
] | |
} | |
] | |
} | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment