我的映射如下所示。 " BID":{ "输入":" string" }, " REGION":{ "输入":" string" },
现在我正在尝试搜索BID值为B100,B302的记录。我在下面写了一下查询。虽然我有这些ID值的记录,但我没有得到任何结果。我在做错的任何线索?
{"查询":{"已过滤":{"过滤":{"条款":{" BID&# 34;:[" B100"," B302"]}}}}}}
答案 0 :(得分:1)
尝试使用小写值,例如:
{"query": {"filtered": {"filter": {"terms": {"BID": ["b100","b302"]}}}}}
您需要执行此操作,因为您未在映射中的"BID"
定义中指定分析器,因此使用默认standard analyzer,这会将字母转换为小写。< / p>
或者,如果您希望在索引术语中维护大小写,可以将"index": "not_analyzed"
添加到"BID"
的映射定义中。
要测试我设置了这样的索引:
PUT /test_index
{
"mappings": {
"doc": {
"properties": {
"BID": {
"type": "string",
"index": "not_analyzed"
},
"REGION": {
"type": "string"
}
}
}
}
}
添加了一些文档:
POST /test_index/doc/_bulk
{"index":{"_id":1}}
{"REGION":"NA","BID":"B100"}
{"index":{"_id":2}}
{"REGION":"NA","BID":"B200"}
{"index":{"_id":3}}
{"REGION":"NA","BID":"B302"}
现在您的查询工作如下:
POST /test_index/_search
{
"query": {
"filtered": {
"filter": {
"terms": {
"BID": [
"B100",
"B302"
]
}
}
}
}
}
...
{
"took": 1,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"failed": 0
},
"hits": {
"total": 2,
"max_score": 1,
"hits": [
{
"_index": "test_index",
"_type": "doc",
"_id": "1",
"_score": 1,
"_source": {
"REGION": "NA",
"BID": "B100"
}
},
{
"_index": "test_index",
"_type": "doc",
"_id": "3",
"_score": 1,
"_source": {
"REGION": "NA",
"BID": "B302"
}
}
]
}
}
以下是我用于测试的一些代码:
http://sense.qbox.io/gist/b4b4767501df7ad8b6459c4d96809d737a8811ec