2014-07-09 4 views
0

시스템 환경에 json 객체가 있습니다. 나는 그 퍼콜 레이터를 environment variable does not contain a variable name "JAVA_HOME"이라면 JAVA_HOME's value is not present in PATH variable이라고도 써야합니다. 이것이 Elasticsearch에서 가능합니까?elasticsearch 속성에 값이 존재하지 않는지 확인하는 방법은 무엇입니까?

은 아래 문서는 중첩이 있기 때문에 먼저 nested mapping 필요 내 여과기

PUT /eg/.percolator/2 
{ 
    "query": { 
     "filtered": { 
      "query": { 
       "bool": { 
        "must": [ 
         { 
          "match": { 
          "client.name": "Athena" 
          } 
         }, 
         { 
          "match": { 
          "[email protected]": "JAVA_HOME" 
          } 
         } 
        ]     
       }    
      } 
     } 
    } 
} 

내 문서

GET /eg/message/_percolate 
{ 
    "doc": { 
     "client": { 
      "name": "Athena", 
      "environment": { 
       "variable": [ 
        { 
         "@name": "JAVA_HOME", 
         "@value": "/home/vikrant/Linux/Sandra/java" 
        }, 
        { 
         "@name": "PATH", 
         "@value": "/bin:/sbin:/usr/bin:/usr/sbin:/home/vikrant/Linux/FAS611:/home/vikrant/Linux/FAS611/odbc:/home/vikrant/Linux/Sandra/java/bin:/home/vikrant/Linux/Sandra/server/bin:.:/bin:/usr/bin:/sbin:/usr/sbin:/usr/bin/X11:/usr/local/bin:/usr/local/etc:/etc:/usr/etc:.:/databases/ORACLE/bin:/databases/SYBASE/OCS-15_0/bin:/databases/DB2/bin:/usr/odbc/bin" 
        } 
       ] 
      } 
     } 
    } 
} 
+0

현재 검색어가 제대로 작동합니까? 귀하의 문서가 중첩되어 있습니다. – vaidik

답변

0

입니다. 그것을

{ 
    "query": { 
    "filtered": { 
     "query": { 
     "bool": { 
      "must": [ 
      { 
       "nested": { 
       "path": "client", 
       "query": { 
        "match": { 
        "client.name": "Athena" 
        } 
       } 
       } 
      }, 
      { 
       "nested": { 
       "path": "client.environment.variable", 
       "query": { 
        "match": { 
        "[email protected]": "JAVA_HOME" 
        } 
       } 
       } 
      } 
      ] 
     } 
     } 
    } 
    } 
} 

귀하의 질문에 오는 : 예상대로

{ 
    "nested_exp": { 
    "properties": { 
     "client": { 
     "type": "nested", 
     "properties": { 
      "environment": { 
      "type": "nested", 
      "properties": { 
       "variable": { 
       "type": "nested", 
       "properties": { 
        "@name": { 
        "type": "string" 
        }, 
        "@value": { 
        "type": "string" 
        } 
       } 
       } 
      } 
      }, 
      "name": { 
      "type": "string" 
      } 
     } 
     } 
    } 
    } 
} 

그런 다음 나는 그것이 작동하도록하기 위해 제공되는 쿼리를 변경 : 이것은 내가 처음 사물이 작동하는 확인하기 위해 문서에 대해 작성한 매핑 두 부분으로 구성됩니다.

첫 번째 부분에서는 NOT 필터에 nested 일치 필터를 사용할 수 있습니다. 다음과 같은 내용 :

{ 
    "query": { 
    "filtered": { 
     "query": { 
     "bool": { 
      "must": [ 
      { 
       "nested": { 
       "path": "client", 
       "query": { 
        "match": { 
        "client.name": "Athena" 
        } 
       } 
       } 
      }, 
      { 
       "filtered": { 
       "query": { 
        "match_all": {} 
       }, 
       "filter": { 
        "not": { 
        "filter": { 
         "nested": { 
         "path": "client.environment.variable", 
         "query": { 
          "match": { 
          "[email protected]": "JAVA_HOME" 
          } 
         } 
         } 
        } 
        } 
       } 
       } 
      } 
      ] 
     } 
     } 
    } 
    } 
} 

로컬 Elasticsearch 서버에서 방금 시도해 보니 매력적입니다.

두 번째 것은 value of 1 variable should not be present in another variable's value과 같이 무엇을 쿼리해야 하느냐에 따라 Elasticsearch로 구현하는 것이 어려워 보입니다.

+0

[관련 질문] 도와주세요. (http://stackoverflow.com/questions/24690293/how-to-match-an-array-value-by-its-key-in-a-key-value -pair-elasticsearch-array)? 감사 – abi1964

관련 문제