2013-03-24 2 views
2

У меня есть следующие параметры, настроенные для индексирования «» asset_test в elasticsearch:запрашивая 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" 
     } 
    } 
} 

Kinda застрял на том, как это сделать Работа.

* Обновление: Я сделал «атрибуты» вложенный тип и запрос с помощью следующего запроса теперь, кажется, работают:

{ 
    "query" : { 
     "nested" : { 
     "path" : "attributes", 
     "query" : { 
      "term" : { 
      "attributes.categories.path" : "/Airport/Hangar 1" 
      } 
     } 
     } 
    } 
} 

Собираюсь ли я об этом правильном пути?

+0

Ваш Вложенный запрос выглядит хорошо. Причина, по которой ваш полевой запрос (возможно) не работает, заключается в том, что он использует query_string, который выполняет шаг предварительной обработки. «/ Аэропорт» предварительно обрабатывается в «Аэропорт», и этот токен не существует в индексе, чтобы он не соответствовал. Оформить заказ [Inquisitor] (https://github.com/polyfractal/elasticsearch-inquisitor) плагин, чтобы помочь играть с запросами, что отлично подходит для отладки этих проблем. – Zach

+0

@Troy, было бы хорошо, если бы вы включили свое обновление в ответ. Я бы сделал это за вас, но вы должны получить за это кредит. –

+0

Я изменил свое обновление в ответ ... спасибо Ноэлю. – Troy

ответ

1

* Обновления: Я сделал «атрибуты» вложенный типа и запрос с помощью следующего запроса теперь, кажется, работает:

{ 
    "query" : { 
     "nested" : { 
     "path" : "attributes", 
     "query" : { 
      "term" : { 
      "attributes.categories.path" : "/Airport/Hangar 1" 
      } 
     } 
     } 
    } 
} 
Смежные вопросы