2
我在elasticsearch配置了“asset_test人指数进行如下设置:查询elasticsearch多场
{
"settings" : {
"analysis" : {
"analyzer" : {
"str_filtered_search_analyzer" : {
"tokenizer" : "keyword",
"filter" : ["lowercase"]
},
"str_prefix_analyzer" : {
"tokenizer" : "keyword",
"filter" : ["lowercase", "prefix"]
},
"str_substring_analyzer" : {
"tokenizer" : "keyword",
"filter" : ["lowercase", "substring"]
},
"path_analyzer" : {
"type" : "custom",
"tokenizer" : "path_hierarchy"
}
},
"filter" : {
"prefix" : {
"type" : "edgeNGram",
"min_gram" : 2,
"max_gram" : 24,
"side": "front"
},
"substring" : {
"type" : "nGram",
"min_gram" : 2,
"max_gram" : 24
}
}
}
},
"mappings" : {
"asset" : {
"properties" : {
"_id": {
"type" : "string",
"index" : "not_analyzed"
},
"_rev": {
"type" : "string",
"index" : "not_analyzed"
},
"type": {
"type" : "string",
"index" : "not_analyzed"
},
"requiredBySystem": {
"type" : "boolean"
},
"attributes": {
"properties" : {
"id" : {
"type" : "string"
},
"type" : {
"type" : "string",
"index" : "not_analyzed"
},
"heading" : {
"type" : "string"
},
"text" : {
"type" : "string"
},
"users" : {
"type" : "string"
},
"categories" : {
"type" : "multi_field",
"fields" : {
"categories" : {
"type" : "string",
"index" : "not_analyzed"
},
"path" : {
"type" : "string",
"analyzer" : "path_analyzer"
}
}
},
"choices" : {
"properties" : {
"text" : {
"type" : "string"
},
"checked" : {
"type" : "boolean"
}
}
},
"requiredBySystem": {
"type" : "boolean"
},
"required": {
"type" : "boolean"
}
}
}
}
}
}
};
我在该指数文件:
{
"_id": "9399fb27448b1e5dfdca0181620418d4",
"_rev": "14-173e71c77d32f0360f7afb2206b2a334",
"type": "entryForm",
"requiredBySystem": true,
"formName": "Basic",
"attributes": [
{
"id": "9399fb27448b1e5dfdca01816203d609",
"type": "text",
"heading": "Brand",
"text": "",
"requiredBySystem": true
},
{
"id": "9399fb27448b1e5dfdca01816203dc61",
"type": "text",
"heading": "Model",
"text": "",
"requiredBySystem": true
},
{
"id": "9399fb27448b1e5dfdca01816203decd",
"type": "text",
"heading": "Location",
"text": "",
"requiredBySystem": true
},
{
"id": "9399fb27448b1e5dfdca01816203e68e",
"type": "userSelectMenu",
"heading": "Assigned To",
"users": [
],
"requiredBySystem": true
},
{
"id": "9399fb27448b1e5dfdca01816203e9c9",
"type": "categories",
"heading": "Categories",
"categories": [
"/Airport/Hangar 1",
"/Airport/Hangar 2"
],
"requiredBySystem": true
},
{
"id": "9399fb27448b1e5dfdca01816203ebdd",
"type": "text",
"heading": "Owner ID",
"text": "",
"requiredBySystem": true
},
{
"id": "9399fb27448b1e5dfdca01816203f0da",
"type": "textarea",
"heading": "Description",
"text": "",
"requiredBySystem": true
},
{
"id": "9399fb27448b1e5dfdca01816207uy5a",
"type": "radio",
"heading": "Radio Buttons",
"choices": [
{
"text": "Button 1",
"checked": false
},
{
"text": "Button 2",
"checked": true
}
],
"requiredBySystem": true
},
{
"id": "9399fb27448b1e5dfdca01816205tgh6",
"type": "checkboxes",
"heading": "Checkboxes",
"choices": [
{
"text": "Box 1",
"checked": false
},
{
"text": "Box 2",
"checked": true
}
],
"requiredBySystem": true
},
{
"id": "9399fb27448b1e5dfdca0181620k81gt",
"type": "select",
"heading": "Select Menu",
"choices": [
{
"text": "Option 1",
"checked": false
},
{
"text": "Option 2",
"checked": true
}
],
"requiredBySystem": true
}
]
}
我想用以下查询找到文档,但没有找到:
{
"query": {
"field": {
"attributes.categories.path": "/Airport"
}
}
}
有点卡在如何使这个工作。
*更新:我做了“属性”嵌套类型,现在用下面的查询查询似乎工作:
{
"query" : {
"nested" : {
"path" : "attributes",
"query" : {
"term" : {
"attributes.categories.path" : "/Airport/Hangar 1"
}
}
}
}
}
我要对这个正确的方式?
你嵌套查询看起来不错。您的Field查询(可能)不起作用的原因是因为它使用了query_string,它执行预处理步骤。 “/ Airport”被预处理为“Airport”,并且该标记在索引中不存在,因此它不匹配。查看[Inquisitor]插件(https://github.com/polyfractal/elasticsearch-inquisitor)插件来帮助玩弄查询,这对于调试这些问题非常有用。 – Zach 2013-03-24 14:35:16
@Troy,如果你把你的更新变成答案,那会很好。我会为你做,但你应该得到它的荣誉。 – 2014-03-17 21:40:26
我将我的更新更改为答案......感谢诺埃尔。 – Troy 2014-03-17 23:28:17