Last active
December 27, 2015 18:39
-
-
Save johtani/7371559 to your computer and use it in GitHub Desktop.
rangeフィルタの動作の違い。 string型のフィールドに対して、rangeフィルタで数値範囲で検索するとどうなるか。 文字列として、10から20という範囲で検索するため、100とか2とかもヒットしてしまう。 「register_data.json:登録データ」
「range_query.json:レンジクエリ」
「exact_response.json:無理やりだけど、望んだ結果」
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 -XPOST "http://localhost:9200/numeric_test/hoge/_search" -d' | |
{ | |
"query": { | |
"bool": { | |
"should": [ | |
{ | |
"wildcard": { | |
"fuga": { | |
"value": "1?" | |
} | |
} | |
}, | |
{ | |
"term": { | |
"fuga": { | |
"value": "20" | |
} | |
} | |
} | |
] | |
} | |
} | |
}' | |
結果 | |
{ | |
"took": 85, | |
"timed_out": false, | |
"_shards": { | |
"total": 5, | |
"successful": 5, | |
"failed": 0 | |
}, | |
"hits": { | |
"total": 3, | |
"max_score": 0.35355338, | |
"hits": [ | |
{ | |
"_index": "numeric_test", | |
"_type": "hoge", | |
"_id": "3", | |
"_score": 0.35355338, | |
"_source": { | |
"fuga": "15" | |
} | |
}, | |
{ | |
"_index": "numeric_test", | |
"_type": "hoge", | |
"_id": "1", | |
"_score": 0.35355338, | |
"_source": { | |
"fuga": "10" | |
} | |
}, | |
{ | |
"_index": "numeric_test", | |
"_type": "hoge", | |
"_id": "4", | |
"_score": 0.04500804, | |
"_source": { | |
"fuga": "20" | |
} | |
} | |
] | |
} | |
} |
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 -XPOST "http://localhost:9200/numeric_test/hoge/_search" -d' | |
{ | |
"query": { | |
"range": { | |
"fuga": { | |
"from": 10, | |
"to": 20 | |
} | |
} | |
} | |
}' | |
結果 | |
{ | |
"took": 54, | |
"timed_out": false, | |
"_shards": { | |
"total": 5, | |
"successful": 5, | |
"failed": 0 | |
}, | |
"hits": { | |
"total": 5, | |
"max_score": 1, | |
"hits": [ | |
{ | |
"_index": "numeric_test", | |
"_type": "hoge", | |
"_id": "3", | |
"_score": 1, | |
"_source": { | |
"fuga": "15" | |
} | |
}, | |
{ | |
"_index": "numeric_test", | |
"_type": "hoge", | |
"_id": "2", | |
"_score": 1, | |
"_source": { | |
"fuga": "2" | |
} | |
}, | |
{ | |
"_index": "numeric_test", | |
"_type": "hoge", | |
"_id": "1", | |
"_score": 1, | |
"_source": { | |
"fuga": "10" | |
} | |
}, | |
{ | |
"_index": "numeric_test", | |
"_type": "hoge", | |
"_id": "5", | |
"_score": 1, | |
"_source": { | |
"fuga": "100" | |
} | |
}, | |
{ | |
"_index": "numeric_test", | |
"_type": "hoge", | |
"_id": "4", | |
"_score": 1, | |
"_source": { | |
"fuga": "20" | |
} | |
} | |
] | |
} | |
} |
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 -XPUT "http://localhost:9200/numeric_test/hoge/1" -d' | |
{ | |
"fuga" : "10" | |
}' | |
curl -XPUT "http://localhost:9200/numeric_test/hoge/2" -d' | |
{ | |
"fuga" : "2" | |
}' | |
curl -XPUT "http://localhost:9200/numeric_test/hoge/3" -d' | |
{ | |
"fuga" : "15" | |
}' | |
curl -XPUT "http://localhost:9200/numeric_test/hoge/4" -d' | |
{ | |
"fuga" : "20" | |
}' | |
curl -XPUT "http://localhost:9200/numeric_test/hoge/5" -d' | |
{ | |
"fuga" : "100" | |
}' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment