简体   繁体   中英

Searching documents indexed via ingest-attachment in elasticsearch

Searching documents indexed via ingest-attachment in elastic search on basis of attributes.

i'm new to elastic search and wanted to index files with some of the attributes like Author, Title, Subject, Category, Community etc.

How far i reached :-

i was able to create a attachment pipeline and was able to ingest the different docs in the elastic with attributes. see below how i did:-

1) created pipeline by following request:-

{  
"description":"Extract attachment information",
"processors":[  
  {  
     "attachment":{  
        "field":"data"
     }
  }
]
}

2) upload an attachment via following code :-

{
"filename":"Presentations-Tips.ppt",
"Author":"Jaspreet",
"Category":"uploading ppt",
"Subject":"testing ppt",
"fileUrl":"",
"attributes": 
{"attr11":"attr11value","attr22":"attr22value","attr33":"attr33value"},
"data": "here_base64_string_of_file"
}

3) then able to search freely on the all the above attributes and on file content as well:-

 {
 "query":{
 "query_string":{
    "query":"*test*"
 }
 }
 }

Now what I wanted is :- Wanted to narrow down the searches through some filters like :-

  1. wanted to search on basis like search on specific parameters like search all those whose author must "Rohan"
  2. then search all whose author must be "Rohan" and category must be "Education"
  3. then search all whose author has letters like "han" and categories has letters "Tech"
  4. search all whose author is "Rohan" and can search full text search on all fields which can have "progress" in any field, means first narrow down search for author and then full text search on those resultset fields.

Please help me with proper query syntax and call url like for above full text search I used 'GET /my_index/_search'

After spending some time finally got the answer:-

curl -X POST \
  http://localhost:9200/my_index/_search \
  -H 'Content-Type: application/json' \
  -d '{
    "query": {
        "bool": {
            "must": [
                {
                    "query_string": {
                        "query": "progress"
                    }
                },
                {
                    "wildcard": {
                        "Author": "Rohan"
                    }
                },
                {
                    "wildcard": {
                        "Title": "q*"
                    }
                }
            ]
        }
    }
}'

now in above you can remove or add any object in must array as per your need.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM